How do I run a single test using Jest?

后端 未结 14 1876
轮回少年
轮回少年 2020-12-12 10:22

I have a test \'works with nested children\' within the file fix-order-test.js.

Running the below runs all the tests in the file.

jest fix-order-test         


        
14条回答
  •  生来不讨喜
    2020-12-12 10:46

    Just a little add-on, because it seems there was kind of a fight if to use ./node_modules/.bin/jest -i ... or just jest -i ... or npm test -- -i ...

    1. Just calling jest works if you have it installed globally (as with npm install -g jest), a not-so-clean way of handling dependencies
    2. If you have Jest installed only locally in the package and want to call the Jest script without the npm script detour, you can use npx jest -i ... => this is exactly what npx is for. It saves you from writing ./node_modules/.bin/....

提交回复
热议问题