Skip to content

Commit c7f56d1

Browse files
authored
docs: how to use 'rootHooks' in the browser (#4755) [ci skip]
1 parent 8421974 commit c7f56d1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/index.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ const fn = async x => { return new Promise(
429429

430430
describe('my suite', function() {
431431
it(`expected value ${z}`, function() {
432-
assert.equal(z, 6);
432+
assert.strictEqual(z, 6);
433433
});
434434
});
435435

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

440440
## Pending Tests
441441

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

444444
```js
445445
describe('Array', function() {
@@ -752,13 +752,11 @@ import assert from 'assert';
752752

753753
// top-level await: Node >= v14.8.0 with ESM test file
754754
const tests = await new Promise(resolve => {
755-
setTimeout(() => {
756-
resolve([
755+
setTimeout(resolve, 5000, [
757756
{args: [1, 2], expected: 3},
758757
{args: [1, 2, 3], expected: 6},
759758
{args: [1, 2, 3, 4], expected: 10}
760-
]);
761-
}, 5000);
759+
]);
762760
});
763761

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

13901388
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.
13911389

1390+
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)
1391+
13921392
### Defining a Root Hook Plugin
13931393

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

0 commit comments

Comments
 (0)