diff --git a/doc/api/test.md b/doc/api/test.md index 24dbd5ec5cd3..27e3ac0b246d 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -2601,6 +2601,19 @@ test('mocks a counting function', (t) => { }); ``` +The following example creates a mock function that throws an error and uses +[`assert.throws`][] to verify it. + +```js +test('mocks a function that throws an error', (t) => { + const fn = t.mock.fn(() => { + throw new Error('mocked error'); + }); + + assert.throws(fn, /mocked error/); +}); +``` + ### `mock.getter(object, methodName[, implementation][, options])`