Reputation: 341
I'm writing several test suites (using Jest and Puppeteer) to automate tests of my AngularJS app's home page. At this point, I have nearly 70 tests in one of my test files (aka test suite). And I'm wondering if it's possible to pass an array of test names to Jest's -t
option to run a specific subset of tests in one of my test files. This will be helpful for debugging, as I have some tests that are interdependent and thus always need to be run together, but it would be nice to avoid having to run the entire test suite (which runs in about a minute) every time I want to debug a few tests.
I've been reading the Jest docs and so far I've come across a few CLI options that have the potential to solve this problem, but have not been fruitful so far.
jest name-of-test-file.spec.js
: This runs all the tests in a single test file, but I don't want to do that, I just want to run a specific subset of tests in a test file.
jest name-of-test-file.spec.js -t name-of-test
: This only runs a single test in a test file, but I want to run a few different interdependent tests.
jest name-of-test-file.spec.js --testPathPattern=<regex>
: This runs all the tests whose names match the regex pattern I pass. It could be helpful but so far I haven't been able to come up with a valid regex that matches against three unique strings (i.e. test names). Unfortunately my test names differ greatly so it would be hard for me to come up with a more generalized regex to match the specific tests I want to run.
I think option 3 has the most potential, but I haven't been able to find a working regex.
Upvotes: 2
Views: 1116
Reputation: 25270
If the regex
option does not work for you, you can use it.only
(or test.only
) to only run specific tests inside a module.
Quote from the docs:
When you are debugging a large codebase, you will often only want to run a subset of tests. You can use
.only
to specify which tests are the only ones you want to run.
Code Sample
it.only('This test will run', /*... */);
it.only('This test will also run', /*... */);
it('This test will not run', /*... */);
However, you still need to specify which module or file to run in case you are having multiple test files:
jest name-of-test-file-to-run.spec.js
Upvotes: 2