如何使用 Jest 运行单个测试? [英] How do I run a single test using Jest?
问题描述
我在文件 fix-order-test.js 中有一个与嵌套子项一起工作"的测试.
I have a test 'works with nested children' within the file fix-order-test.js.
运行以下命令会运行文件中的所有测试.
Running the below runs all the tests in the file.
jest fix-order-test
如何只运行一个测试?以下在搜索指定的正则表达式文件时不起作用.
How do I run only a single test? The below does not work as it searches for a file of the regex specified.
jest 'works with nested children'
推荐答案
从命令行,使用 --testNamePattern
或 -t
标志:
From the command line, use the --testNamePattern
or -t
flag:
jest -t 'fix-order-test'
这只会运行与您提供的测试名称模式匹配的测试.它位于 Jest 文档中.
This will only run tests that match the test name pattern you provide. It's in the Jest documentation.
另一种方法是在监视模式下运行测试,jest --watch
,然后按 P 通过键入测试文件名或 过滤测试T 运行单个测试名称.
Another way is to run tests in watch mode, jest --watch
, and then press P to filter the tests by typing the test file name or T to run a single test name.
如果你在 describe
块中有一个 it
,你必须运行
If you have an it
inside of a describe
block, you have to run
jest -t '<describeString> <itString>'
这篇关于如何使用 Jest 运行单个测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!