我在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,它使这个过程更加简单。
以下是我的看法:
./node_modules/.bin/jest --config test/jest-unit-config.json --runInBand src/components/OpenForm/OpenForm.spec.js -t 'show expanded'
注:
./node_modules/.bin/... is a wonderful way, to access the locally installed Jest (or Mocha or...) binary that came with the locally installed package. (Yes, in your npm scripts you can jest with nothing before, but this is handy on command line... (that's also a good start for your debugging config, whichever IDE you are using...) Your project might not have a set of configuration options. But if it does (peek into the scripts in package.json), this is, what you need. --runInBand – as said, don't know about your configuration, but if you concentrate on developing/fixing a single test, you rather do not want to deal with web workers... Yes, you can give the whole, explicit path to your file Optionally, you can use -t to not run all tests in that file, but only a single one (here: the one, that has something with ‘show expanded’ in its name). Same effect can be achieved by glueing .only() into that file.
在最新版本的jest中,您可以以多种方式运行任何单个测试。
fit('only this test will run', () => {});
it.only('only this test will run',() => {});
在Visual Studio Code中,这让我只能运行/调试一个带有断点的Jest测试:在Visual Studio Code中调试测试
我的发射。Json文件里面有这个:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}
在package.json文件中:
"scripts": {
"test": "jest"
}
要运行一个测试,在该测试中,将test(或it)更改为test。只有(或it.only)。若要运行一个测试套件(多个测试),请将describe更改为description .only。 如果需要,可以设置断点。 在Visual Studio Code中,转到调试视图(Shift + Cmd + D或Shift + Ctrl + D)。 从顶部的下拉菜单中,选择笑话当前文件。 单击绿色箭头以运行该测试。
对于Windows中的VSCode,我在我的启动中使用这些。json文件。注意使用${pathSeparator}来处理Win和Mac中的差异。在调试下拉菜单中选择一个并按F5运行。
{
"name": "Debug Selected Jest Test",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/jest/bin/jest.js", "--runInBand"],
"args": ["--", "-i", "${fileDirnameBasename}${pathSeparator}${fileBasename} ", "-t", "${selectedText}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},
{
"name": "Debug Named Jest Test",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/jest/bin/jest.js", "--runInBand"],
"args": ["--", "-i", "${fileDirnameBasename}${pathSeparator}${fileBasename} ", "-t", "filename.test.js"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},