Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'pending' test mean in Mocha, and how can I make it pass/fail?

Tags:

I am running my tests and noticed:

18 passing (150ms) 1 pending 

I haven't seen this before. Previously test either passed, or failed. Timeouts caused failures. I can see which test is failing because it's also blue. But it has a timeout on it. Here's a simplified version:

test(`Errors when bad thing happens`), function(){   try {     var actual = doThing(option)           } catch (err) {     assert(err.message.includes('invalid'))   }   throw new Error(`Expected an error and didn't get one!`) } 
  • What does 'pending' mean? How could a test be 'pending' when Mocha has exited and node is no longer running?
  • Why is this test not timing out?
  • How can I make the test pass or fail?

Thanks!

like image 783
mikemaccana Avatar asked Mar 01 '18 13:03

mikemaccana


People also ask

What does pending mean in Mocha?

For Mocha, the documentation says that a pending test is a test without any callback.

What are pending tests?

A test that has been selected to run but is not yet in progress.

How do you skip the Mocha test?

This inclusive ability is available in Mocha by appending . skip() to the suite or to specific test cases. The skipped tests will be marked as "pending" in the test results.

How can we make individual specs pending?

Aditionally, there is a pending() function you can call anywhere inside a spec to mark it as pending: it("can be declared by calling 'pending' in the spec body", function() { expect(true). toBe(false); pending(); });


1 Answers

A test can end up being shown by Mocha as "pending" when you inadvertently closed the test's it method early, like:

// Incorrect -- arguments of the it method are closed early it('tests some functionality'), () => {   // Test code goes here... }; 

The it method's arguments should include the test function definition, like:

// Correct it('tests some functionality', () => {   // Test code goes here... }); 
like image 118
Jon Schneider Avatar answered Sep 18 '22 17:09

Jon Schneider