From c7f56d13f2bf64befef42ad8299d720e2eb42152 Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Fri, 24 Sep 2021 14:59:41 +0200 Subject: [PATCH] docs: how to use 'rootHooks' in the browser (#4755) [ci skip] --- docs/index.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/index.md b/docs/index.md index 9245867d0e..a47a4d46ea 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: ```js describe('Array', function() { @@ -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 @@ -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 `. @@ -2142,6 +2142,7 @@ mocha.setup({ forbidPending: true, global: ['MyLib'], retries: 3, + rootHooks: { beforeEach(done) { ... done();} }, slow: '100', timeout: '2000', ui: 'bdd'