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?
it.only
anddescribe.only
work only for the module they are in. If you are having problems to filter tests in multiple files, you can usejest -t name-of-spec
, filtering tests that match the spec name (match against the name in describe or test).Source: https://facebook.github.io/jest/docs/en/cli.html
For example, I focus the test which I'm currently writing like this (with the test script in the
package.json
):npm test -- -t "test foo"
it's like this:
it will test all files with the name
sometest.test.js
and matching based on -t option, if you only want to test a specific file you can do this:fit
,fdescribe
andit.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 likeYou can filter tests by a
testname
orfilename
, just follow instructions in the terminalPress
p
, then type a filenameThen you can use
describe.only
andit.only
which will skip all other tests from filtered, tested file.For me it works if I use 2 params like this:
--watch: is optional
-f: will do filtering of your files, so if you have a lot of tests with same name, specify fullpath to exact file
-t: works with 'describe' name or 'it' name of your test