我在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'
当前回答
只是一个小插件,因为如果使用。/node_modules/.bin/jest -i…或者只是开玩笑-我…或者NPM测试-我…
如果你在全局安装了jest(如npm install -g jest),那么只调用jest就可以了,这是一种不太干净的处理依赖关系的方式 如果Jest只安装在包的本地,并且想调用Jest脚本而不需要绕道npm脚本,你可以使用npx Jest -i…=>这正是NPX的目的。它可以节省编写。/node_modules/.bin/....的时间
其他回答
我花了一段时间才找到这个,所以我想在这里为像我这样使用纱线的人添加它:
yarn test -i "src/components/folderX/folderY/.../Filename.ts" -t "name of test"
文件名在-i后面,testname在-t后面。
NPM test __tests__/filename.test。t -运行单个文件。
测试。only('check single test', () => {expect(true).toBe(true)});-运行单个测试用例
测试。skip('跳过testcase, () => {expect(false).toBe(false_});-跳过一个测试用例
您还可以使用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);
});
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);
});
只是一个小插件,因为如果使用。/node_modules/.bin/jest -i…或者只是开玩笑-我…或者NPM测试-我…
如果你在全局安装了jest(如npm install -g jest),那么只调用jest就可以了,这是一种不太干净的处理依赖关系的方式 如果Jest只安装在包的本地,并且想调用Jest脚本而不需要绕道npm脚本,你可以使用npx Jest -i…=>这正是NPX的目的。它可以节省编写。/node_modules/.bin/....的时间