Run only ONE test with Jest

jpenna picture jpenna · Jun 9, 2017 · Viewed 83.5k times · Source

Very simple, I want to run just one test with Jest.

I put 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 to run a single test?

Answer

Dawid Karabin picture Dawid Karabin · Jun 9, 2017

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 still run all other test files in your project.

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

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


Use 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 instructions in the terminal

enter image description here

Press p, then type a filename

enter image description here

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