Javascript 跳过测试文件 Jest 中的一项测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48125230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Skip one test in test file Jest
提问by Gleichmut
I'm using Jest framework and have a test suite. I want to turn off/skip one of my tests.
我正在使用 Jest 框架并有一个测试套件。我想关闭/跳过我的一项测试。
Googling documentation doesn't give me answers.
谷歌搜索文档没有给我答案。
Do you know the answer or source of information to check?
您知道要检查的答案或信息来源吗?
回答by Gleichmut
I found the answer here
我在这里找到了答案
test('it is raining', () => {
expect(inchesOfRain()).toBeGreaterThan(0);
});
test.skip('it is not snowing', () => {
expect(inchesOfSnow()).toBe(0);
});
回答by Seth McClaine
You can also exclude testor describeby prefixing them with an x.
您还可以排除它们test或describe在它们前面加上x.
Individual Tests
个人测试
describe('All Test in this describe will be run', () => {
xtest('Except this test- This test will not be run', () => {
expect(true).toBe(true);
});
test('This test will be run', () => {
expect(true).toBe(true);
});
});
Multiple tests inside a describe
描述中的多个测试
xdescribe('All tests in this describe will be skipped', () => {
test('This test will be skipped', () => {
expect(true).toBe(true);
});
test('This test will be skipped', () => {
expect(true).toBe(true);
});
});
回答by Yuci
Skip a test
跳过测试
If you'd like to skip a test in Jest, you can use test.skip:
如果您想跳过 Jest 中的测试,可以使用test.skip:
test.skip(name, fn)
Which is also under the following aliases:
这也在以下别名下:
it.skip(name, fn)orxit(name, fn)orxtest(name, fn)
it.skip(name, fn)或者xit(name, fn)或者xtest(name, fn)
Skip a test suite
跳过测试套件
Additionally, if you'd like to skip a test suite, you can use describe.skip:
此外,如果您想跳过测试套件,可以使用describe.skip:
describe.skip(name, fn)
Which is also under the following alias:
这也在以下别名下:
xdescribe(name, fn)
xdescribe(name, fn)

