Sunday, June 2, 2024
19
rated 0 times [  23] [ 4]  / answers: 1 / hits: 180304  / 7 Years ago, thu, june 8, 2017, 12:00:00

I want to run just one test with Jest.


I use it.only or describe.only, but it still runs a whole lot of tests. I think it runs all the tests since my last commit, but it shouldn't have this behavior with the only flag explicitly set, right?


What causes this behavior and how can I run a single test?


More From » unit-testing

 Answers
117

Jest parallelizes test runs and it doesn't know upfront which tests it
should run and which it shouldn't run.
This means when you use "fit", it will only run one test in that file.
But it still runs all other test files in your project
.



fit, fdescribe and it.only, describe.only have the same purpose: skip other tests and run only me.


Source: https://github.com/facebook/jest/issues/698#issuecomment-177673281




Use the Jest filtering mechanism. When you run your tests like,


jest --config=jest.config.json --watch

you can filter tests by a testname or filename. Just follow the instructions in the terminal.


Enter


Press p, and then type a filename.


Enter


Then you can use describe.only and it.only which will skip all other tests from the filtered, tested file.


[#57519] Wednesday, June 7, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darleneh

Total Points: 231
Total Questions: 110
Total Answers: 94

Location: Spain
Member since Thu, Dec 23, 2021
2 Years ago
;