☕️ Classic, reliable, trusted test framework for Node.js and the browser
docs: how to use 'rootHooks' in the browser (#4755) [ci skip]
Juerg Bc7f56d13f2bf
diff --git a/docs/index.md b/docs/index.mdindex 9245867d..a47a4d46 100644--- a/docs/index.md+++ b/docs/index.md@@ -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);});});@@ -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:```jsdescribe('Array', function() {@@ -752,13 +752,11 @@ import assert from 'assert';// top-level await: Node >= v14.8.0 with ESM test fileconst 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@@ -1389,6 +1387,8 @@ In some cases, you may want a [hook](#hooks) before (or after) every test in eveA _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 PluginA 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({forbidPending: true,global: ['MyLib'],retries: 3,+ rootHooks: { beforeEach(done) { ... done();} },slow: '100',timeout: '2000',ui: 'bdd'