本文介绍了使用 Jest 仅运行一项测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想用 Jest 运行一项测试.

我使用 it.onlydescribe.only,但它仍然运行大量测试.我认为它运行了自我上次提交以来的所有测试,但它不应该在显式设置 only 标志的情况下具有这种行为,对吗?

是什么导致了这种行为,我该如何运行单个测试?

解决方案

fitfdescribeit.onlydescribe.only 具有相同的目的:跳过其他测试只跑我.

来源:

p,然后输入文件名.

然后您可以使用 describe.onlyit.only ,这将跳过过滤后的测试文件中的所有其他测试.

I want to run just one test with Jest.

I use it.only or describe.only, but it still runs a whole lot of tests. I think it runs all the tests since my last commit, but it shouldn't have this behavior with the only flag explicitly set, right?

What causes this behavior and how can I run a single test?

解决方案

fit, fdescribe and it.only, describe.only have the same purpose: skip other tests and run only me.

Source: https://github.com/facebook/jest/issues/698#issuecomment-177673281


Use the Jest filtering mechanism. When you run your tests like,

jest --config=jest.config.json --watch

you can filter tests by a testname or filename. Just follow the instructions in the terminal.

Press p, and then type a filename.

Then you can use describe.only and it.only which will skip all other tests from the filtered, tested file.

这篇关于使用 Jest 仅运行一项测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 11:35