diff --git a/doc/api/test.md b/doc/api/test.md index d86c2cfc0bfb13..f7ce098125e4e2 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -1364,6 +1364,10 @@ changes: * `timeout` {number} A number of milliseconds the test will fail after. If unspecified, subtests inherit this value from their parent. **Default:** `Infinity`. + * `plan` {number} The number of assertions expected to be run in the test. + If the number of assertions run in the test does not match the number + specified in the plan, the test will fail. + **Default:** `undefined`. * `fn` {Function|AsyncFunction} The function under test. The first argument to this function is a [`TestContext`][] object. If the test uses callbacks, the callback function is passed as the second argument. **Default:** A no-op @@ -2965,6 +2969,29 @@ added: The name of the test. +### `context.plan(count)` + + + +* `count` {number} The number of assertions that are expected to run. + +This function is used to set the number of assertions that are expected to run +within the test. If the number of assertions that run does not match the +expected count, the test will fail. + +> Note: To make sure assertion are tracked, it must be used `t.assert` instead of `assert` directly. + +```js +test('top level test', (t) => { + t.plan(2); + t.assert.ok('some relevant assertion here'); + t.assert.ok('another relevant assertion here'); +}); +``` + ### `context.runOnly(shouldRunOnlyTests)`