我在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'
当前回答
我发现最快/最简单的方法是用
npx 是 TheNameOfYourFile
此外,您可以“订阅”以继续阅读更改
npx 是 TheNameOfYourFile --watchAll
其他回答
现在有一个很好的Jest插件,叫做joke -watch-typeahead,它使这个过程更加简单。
NPM test __tests__/filename.test。t -运行单个文件。
测试。only('check single test', () => {expect(true).toBe(true)});-运行单个测试用例
测试。skip('跳过testcase, () => {expect(false).toBe(false_});-跳过一个测试用例
如果你把jest作为脚本命令运行,比如npm test,你需要使用下面的命令让它工作:
npm test -- -t "fix order test"
您还可以使用f或x来集中或排除一个测试。例如
fit('only this test will run', () => {
expect(true).toBe(false);
});
it('this test will not run', () => {
expect(true).toBe(false);
});
xit('this test will be ignored', () => {
expect(true).toBe(false);
});
对于VSCode,你可以使用joke -run-it扩展,它将帮助你从编辑器中运行和调试Jest测试。