使用 Jest 仅运行一项测试 [英] Run only ONE test with Jest

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

问题描述

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

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

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

解决方案

Jest 并行化测试运行,但它不知道预先测试的是哪个应该运行,哪些不应该运行.这意味着当您使用fit"时,它只会在该文件中运行一项测试.但它仍会运行您项目中的所有其他测试文件.

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?

解决方案

Jest parallelizes test runs and it doesn't know upfront which tests it should run and which it shouldn't run. This means when you use "fit", it will only run one test in that file. But it still runs all other test files in your project.

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 仅运行一项测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆