93

I'm using Jest framework and have a test suite. I want to turn off/skip one of my tests.

Googling documentation doesn't give me answers.

Do you know the answer or source of information to check?

Seth McClaine
  • 6,298
  • 4
  • 32
  • 53
Gleichmut
  • 3,806
  • 3
  • 20
  • 29
  • Just commenting it out? – Skam Jan 06 '18 at 07:39
  • 2
    It is not right way to deal test you want to skip by intent. At least such behavior doesn't pass software quality check in our team. (though I have one example of commented test in legacy code) – Gleichmut Jan 06 '18 at 07:46

3 Answers3

131

I found the answer here

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

Gleichmut
  • 3,806
  • 3
  • 20
  • 29
61

You can also exclude test or describe by prefixing them with an 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);
 });
});
Seth McClaine
  • 6,298
  • 4
  • 32
  • 53
43

Skip a test

If you'd like to skip a test in Jest, you can use 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)

Skip a test suite

Additionally, if you'd like to skip a test suite, you can use describe.skip:

describe.skip(name, fn)

Which is also under the following alias:

  • xdescribe(name, fn)
Yuci
  • 17,258
  • 5
  • 80
  • 93