Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root-Level Hooks not working with --require option #2507

Closed
eschwartz opened this issue Sep 27, 2016 · 3 comments
Closed

Root-Level Hooks not working with --require option #2507

eschwartz opened this issue Sep 27, 2016 · 3 comments
Assignees
Labels
area: documentation anything involving docs or mochajs.org

Comments

@eschwartz
Copy link

According to the docs:

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)
@boneskull
Copy link
Member

My bad

@boneskull boneskull added the area: documentation anything involving docs or mochajs.org label Sep 28, 2016
@boneskull boneskull self-assigned this Sep 28, 2016
@boneskull
Copy link
Member

updated docs to omit the misinformation

@eschwartz
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation anything involving docs or mochajs.org
Projects
None yet
Development

No branches or pull requests

2 participants