jpe*_*nna 62 javascript unit-testing jestjs
很简单,我想用Jest运行一个测试.
我放it.only
或describe.only
但它仍然运行了很多测试.我认为自从我上一次提交以来它运行了所有测试,但它不应该only
明确设置标志的这种行为,对吧?
导致此行为的原因以及如何运行单个测试?
hin*_*nok 69
Jest 并行化了测试运行,它不知道应该运行哪些测试以及哪些测试不应该运行.这意味着当您使用"fit"时,它只会在该文件中运行一个测试,但仍会运行项目中的所有其他测试文件.
fit
,fdescribe
并且it.only
,describe.only
有相同的目的,跳过其他的,只运行我.
资料来源:https://github.com/facebook/jest/issues/698#issuecomment-177673281
使用jest
过滤机制,当你运行你的测试时
jest --config=jest.config.json --watch
Run Code Online (Sandbox Code Playgroud)
您可以通过testname
或过滤测试filename
,只需按照终端中的说明操作即可
按p
,然后键入文件名
然后你可以使用describe.only
和it.only
这将跳过从过滤,测试文件中的所有其他测试.
rod*_*bbi 17
it.only
并且describe.only
仅适用于它们所在的模块.如果您在多个文件中过滤测试时遇到问题,可以使用jest -t name-of-spec
,过滤与规范名称匹配的测试(与describe或test中的名称匹配).
资料来源:https://facebook.github.io/jest/docs/en/cli.html
例如,我关注我正在编写的测试(使用测试脚本package.json
):
npm test -- -t "test foo"
ton*_*nco 14
对我来说,如果我使用两个这样的参数,它会起作用:
yarn test --watch -f "src/...fullpath.../reducer.spec.js" -t "Name of the test"
Run Code Online (Sandbox Code Playgroud)
标志:
--watch: is optional
-f: will do filtering of your files, so if you have a lot of tests with the same name, specify the full path to the exact file
-t: works with 'describe' name or 'it' name of your test
Run Code Online (Sandbox Code Playgroud)
Hos*_*our 13
就像这样:
jest sometest.test.js -t "some expression to match a describe or a test"
Run Code Online (Sandbox Code Playgroud)
它将sometest.test.js
根据 -t 选项测试具有名称和匹配的所有文件。如果你只想测试一个特定的文件,你可以这样做:
jest src/user/.../sometest.test.js
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
45887 次 |
最近记录: |