我在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'
当前回答
开玩笑地说,这是唯一对我有用的东西:
is -- test/unit/name-of-test-file.test.ts
观察
is --watch -- test/unit/name-of-test-file.test.ts
其他回答
Use:
npm run test -- test-name
只有当您的测试规范名称是唯一的时,这才会起作用。
上面的代码将引用一个名为test-name.component.spec.ts的文件
NPM test __tests__/filename.test。t -运行单个文件。
测试。only('check single test', () => {expect(true).toBe(true)});-运行单个测试用例
测试。skip('跳过testcase, () => {expect(false).toBe(false_});-跳过一个测试用例
https://jestjs.io/docs/cli#--testnamepatternregex
你的测试是这个文件my。test。js
test("My Sum", () => {
const sum = 3;
expect(sum).toBe(3);
});
以测试名在CLI上运行
jest -t Sum
使用npm测试与regex匹配部分文件名的例子:my.test.js
npm test -t my
你可以尝试使用下面的命令,因为它对我有用
npm run test -- -t 'Your test name'
或者你可以像下面这样在测试中添加.only,然后运行npm run test命令
it.only('Your test name', () => {})
正如前面的回答所述,您可以运行该命令
jest -t 'fix-order-test'
如果你在描述块中有一个it,你必须运行
jest -t '<describeString> <itString>'