如何使用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
标志
jest -t 'fix-order-test'
这只会运行与您提供的测试名称模式匹配的测试.在笑话文档中.
This will only run tests that match the test name pattern you provide. It's in the Jest docs.
另一种方法是在监视模式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.
这篇关于如何使用Jest运行单个测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!