28

I want to make some of my jest tests pending. How can I do it? API reference doesn't have any method how can I make my test pending.

asiniy
  • 11,816
  • 6
  • 49
  • 117

5 Answers5

28

You can also just say test.todo('Some test I still need to do')

The test runner will then have show a count of tests in a todo state:

Tests: 1 todo, 2 passed, 3 total

Herald Smit
  • 1,976
  • 18
  • 23
15

UPDATED

Since jest@24.0.0 it's now possible to use:

it.todo(...)
test.todo(...)

Which will look like:

Tests:       1 todo, 23 passed, 24 total

OLD ANSWER

Setting tests as Pending per se is not featured in Jest.

However it allows to skip tests by using

it.skip(...)
test.skip(...)

And then they are marked not as passed but skipped:

Tests:       1 skipped, 23 passed, 24 total

Which for me is a very good equivalent to "pending".

Source Skip one test in test file Jest by Gleichmut.

josemigallas
  • 3,058
  • 1
  • 22
  • 60
  • NOTE: `it.todo` and `test.todo` will still run `beforeAll` callbacks, even if the test file doesn't contain any active tests. https://github.com/facebook/jest/issues/11006 – Joshua Pinter May 25 '21 at 17:44
10

You're looking for xit and xdescribe

http://jasmine.github.io/1.3/introduction.html#section-Disabling_Specs_and_Suites

Rodrigo Siqueira
  • 1,134
  • 8
  • 20
  • `xit` and `xdescribe` just make tests passing. Can I show them as pending? – asiniy Aug 24 '15 at 17:58
  • 1
    @asiniy I believe not as [pending](http://jasmine.github.io/2.0/introduction.html#section-Pending_Specs) is only available after jasmine 2.0, and jest uses 1.3 – Rodrigo Siqueira Aug 24 '15 at 18:29
5

Instead of saying test(...), just say xtest(...) and the test will be skipped.

nbkhope
  • 6,516
  • 2
  • 32
  • 53
1

Looks like in the latest version of jest xit and xdescribe will show up as skipped for the default reporter.

If you really need to display pending specs you will need to create a custom reporter.

Here is the link to the jest documentation for setting a custom handler.

Zenchi
  • 21
  • 2
  • Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – baduker Mar 27 '18 at 04:36