Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,29 @@ test('spies on an object method', (t) => {
});
```

The same approach can be used to mock a method that throws and verify the
error with [`assert.throws()`][]:

```js
test('mocks a method that throws', (t) => {
const number = {
value: 5,
subtract(a) {
return this.value - a;
},
};

t.mock.method(number, 'subtract', () => {
throw new Error('boom');
});

assert.throws(() => number.subtract(3), {
message: 'boom',
});
});
```


### `mock.module(specifier[, options])`

<!-- YAML
Expand Down