Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocha 'before each hook' message in red. How do I know what specifically is wrong?

I have the following message, just before a failing test:

1) "before each" hook 

That is the the entire message. It is in red, which makes me think there is something wrong with the before each hook, but I'm unsure of what the error is. It could be:

  • A failed timeout
  • A failed assertion
  • An Error being thrown

How do I know what the error is?

This particular beforeEach() normally executes perfectly fine.

like image 527
mikemaccana Avatar asked Mar 09 '15 11:03

mikemaccana


People also ask

Which of the following is a Mocha hook method?

Mocha provides several built-in hooks that can be used to set up preconditions and clean up after your tests. The four most commonly used hooks are: before() , after() , beforeEach() , and afterEach() .

What is before all hook?

beforeAll HookThis Hook is executed before all tests and, when called in the scope of the test file, runs before all the tests in the file. When used inside the test describe, it runs before all tests in the group. If multiple beforeAll is used, they will run in the order of their registration.

How do I run a specific test file in Mocha?

The exclusivity feature allows you to run only the specified suite or test-case by appending .only() to the function. Here's an example of executing only a particular suite: describe('Array', function () { describe.only('#indexOf()', function () { // ... }); }); Note: All nested suites will still be executed.

Which of the following are incompatible with parallel mode when working with Mocha in testing?

Incompatible options include --sort , --delay , and importantly, --file . In short, it's because we cannot run tests in any specific order.


1 Answers

I ran into this problem when in the beforeEach I accidentally called done() twice (I called it once at the end of the beforeEach, but also called it again via an async function called in the beforeEach).

When I ran the tests in watch mode I got the error message you described without any additional information; when I ran the tests normally I did not get any errors. I reported this on a related ticket.

like image 179
cuttlefish Avatar answered Sep 19 '22 05:09

cuttlefish