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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:01:42  来源:igfitidea点击:

Skip one test in test file Jest

javascriptnode.jstestingjestjs

提问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

我在这里找到了答案

https://devhints.io/jest

https://devhints.io/jest

test('it is raining', () => {
  expect(inchesOfRain()).toBeGreaterThan(0);
});

test.skip('it is not snowing', () => {
  expect(inchesOfSnow()).toBe(0);
});

Link on off doc

文档外链接

回答by Seth McClaine

You can also exclude testor describeby prefixing them with an x.

您还可以排除它们testdescribe在它们前面加上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)or
  • xit(name, fn)or
  • xtest(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)