36

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.

5 Answers 5

32

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
2
  • 1
    Note this is only available in Jest 24+ Commented May 10, 2019 at 20:32
  • 2
    Now with jest v24 this should be the accepted answer. Marking a test as skipped is not quite the same as stating it is pending.
    – Ernesto
    Commented Aug 19, 2019 at 16:03
23

UPDATED

Since [email protected] 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.

1
11

You're looking for xit and xdescribe

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

2
  • xit and xdescribe just make tests passing. Can I show them as pending? Commented Aug 24, 2015 at 17:58
  • 1
    @asiniy I believe not as pending is only available after jasmine 2.0, and jest uses 1.3 Commented Aug 24, 2015 at 18:29
6

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

4
  • Is there a way to add reason which will show up in report? Like in Jasmine: xit().pend('Reason')
    – Gennadiii
    Commented Dec 29, 2017 at 13:53
  • This won't make the test pending but it simply will make it pass. Commented Nov 20, 2018 at 8:35
  • 1
    Actually, it won't make the test pass, it will skip the test entirely. It will be not pending, not failed and not even passed.
    – kekko12
    Commented May 7, 2020 at 15:51
  • I thought that was specific to mocha...?
    – Hyfy
    Commented Mar 25, 2021 at 17:42
2

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.

1
  • 1
    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
    Commented Mar 27, 2018 at 4:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.