我在fix-order-test.js文件中有一个测试“works with nested children”。
运行下面的代码将运行文件中的所有测试。
jest fix-order-test
如何只运行一个测试?下面的方法无法工作,因为它搜索指定的正则表达式的文件。
jest 'works with nested children'
我在fix-order-test.js文件中有一个测试“works with nested children”。
运行下面的代码将运行文件中的所有测试。
jest fix-order-test
如何只运行一个测试?下面的方法无法工作,因为它搜索指定的正则表达式的文件。
jest 'works with nested children'
当前回答
运行命令行:
npm run test-jest unit_test/file_name -- -t test_name
我Package.json
"test-jest": "jest --verbose=true --force-exit",
"test-jest:watch": "jest --watchAll",
其他回答
Jest文档建议如下:
如果测试失败,首先要检查的事情之一应该是 当测试是唯一运行的测试时,测试是否失败。在开玩笑 只运行一个测试很简单——只是临时更改该测试 命令到test.only
test.only('this will be the only test that runs', () => {
expect(true).toBe(false);
});
or
it.only('this will be the only test that runs', () => {
expect(true).toBe(false);
});
如果你把jest作为脚本命令运行,比如npm test,你需要使用下面的命令让它工作:
npm test -- -t "fix order test"
现在有一个很好的Jest插件,叫做joke -watch-typeahead,它使这个过程更加简单。
你可以尝试使用下面的命令,因为它对我有用
npm run test -- -t 'Your test name'
或者你可以像下面这样在测试中添加.only,然后运行npm run test命令
it.only('Your test name', () => {})
NPM test __tests__/filename.test。t -运行单个文件。
测试。only('check single test', () => {expect(true).toBe(true)});-运行单个测试用例
测试。skip('跳过testcase, () => {expect(false).toBe(false_});-跳过一个测试用例