You may also pick any file and add “root”-level hooks. For example, add beforeEach() outside of all describe() blocks. This will cause the callback to beforeEach() to run before any test case, regardless of the file it lives in (this is because Mocha has an implied describe() block, called the “root suite”).
... This is typically done in Node by placing your hook(s) in a .js module, and using the --require /path/to/module option on the command-line.
However, if I attempt to load a "hook" file with --require, I get an error like:
$ mocha --require /path/to/hook/file.js
ReferenceError: before is not defined
at Object.<anonymous> (/path/to/hook/file.js:1:1)
My bad
updated docs to omit the misinformation
Ah.
Can we add docs explaining how to do this properly?
This is working for me:
mocha --recursive /path/to/hook/file.js ./test/spec/
The docs could say something like:
This is typically done in Node by placing your hook(s) in a .js module, and including it in your test run.
For example:
mocha --recursive /path/to/hook/file test/spec
Most helpful comment
Ah.
Can we add docs explaining how to do this properly?
This is working for me:
The docs could say something like: