Skip to content

Commit

Permalink
docs: how to use 'rootHooks' in the browser (#4755) [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Sep 24, 2021
1 parent 8421974 commit c7f56d1
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit c7f56d1

Please sign in to comment.