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
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
-
1
-
2Now with jest v24 this should be the accepted answer. Marking a test as skipped is not quite the same as stating it is pending.– ErnestoCommented Aug 19, 2019 at 16:03
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.
-
NOTE:
it.todo
andtest.todo
will still runbeforeAll
callbacks, even if the test file doesn't contain any active tests. github.com/facebook/jest/issues/11006 Commented May 25, 2021 at 17:44
You're looking for xit
and xdescribe
http://jasmine.github.io/1.3/introduction.html#section-Disabling_Specs_and_Suites
-
xit
andxdescribe
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
Instead of saying test(...)
, just say xtest(...) and the test will be skipped.
-
Is there a way to add reason which will show up in report? Like in Jasmine: xit().pend('Reason') 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
-
1Actually, it won't make the test pass, it will skip the test entirely. It will be not pending, not failed and not even passed.– kekko12Commented May 7, 2020 at 15:51
-
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.
-
1Links 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.– badukerCommented Mar 27, 2018 at 4:36