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:
How do I know what the error is?
This particular beforeEach()
normally executes perfectly fine.
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() .
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.
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.
Incompatible options include --sort , --delay , and importantly, --file . In short, it's because we cannot run tests in any specific order.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With