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

Docs: Usage of 'root hook' plugins in the browser #4755

Merged
merged 1 commit into from Sep 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/index.md
Expand Up @@ -429,7 +429,7 @@ const fn = async x => { return new Promise(

describe('my suite', function() {
it(`expected value ${z}`, function() {
assert.equal(z, 6);
assert.strictEqual(z, 6);
});
});

Expand All @@ -439,7 +439,7 @@ const fn = async x => { return new Promise(

## Pending Tests

"Pending"--as in "someone should write these test cases eventually"--test-cases are those _without_ a callback:
"Pending"as in "someone should write these test cases eventually"test-cases are those _without_ a callback:

```js
describe('Array', function() {
Expand Down Expand Up @@ -752,13 +752,11 @@ import assert from 'assert';

// top-level await: Node >= v14.8.0 with ESM test file
const tests = await new Promise(resolve => {
setTimeout(() => {
resolve([
setTimeout(resolve, 5000, [
{args: [1, 2], expected: 3},
{args: [1, 2, 3], expected: 6},
{args: [1, 2, 3, 4], expected: 10}
]);
}, 5000);
]);
});

// in suites ASYNCHRONOUS callbacks are NOT supported
Expand Down Expand Up @@ -1389,6 +1387,8 @@ In some cases, you may want a [hook](#hooks) before (or after) every test in eve

A _Root Hook Plugin_ is a JavaScript file loaded via [`--require`](#-require-module-r-module) which "registers" one or more root hooks to be used across all test files.

In browsers you can set root hooks directly via a `rootHooks` object: `mocha.setup({ rootHooks: beforeEach() {...} })`, also see [`mocha.setup()`](#running-mocha-in-the-browser)

### Defining a Root Hook Plugin

A Root Hook Plugin file is a script which exports (via `module.exports`) a `mochaHooks` property. It is loaded via `--require <file>`.
Expand Down Expand Up @@ -2142,6 +2142,7 @@ mocha.setup({
forbidPending: true,
global: ['MyLib'],
retries: 3,
rootHooks: { beforeEach(done) { ... done();} },
slow: '100',
timeout: '2000',
ui: 'bdd'
Expand Down