Skip to content

Commit 1caefe1

Browse files
committed
improve t.throws & t.notThrows docs
fixes #1120
1 parent c39b9dc commit 1caefe1

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

readme.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,38 @@ Assert that `value` is not deep equal to `expected`.
905905

906906
Assert that `function` throws an error, or `promise` rejects with an error.
907907

908-
`error` can be a constructor, regex, error message or validation function.
908+
`error` can be an error constructor, error message, regex matched against the error message, or validation function.
909909

910-
Returns the error thrown by `function` or the rejection reason of `promise`.
910+
Returns the error thrown by `function` or a promise for the rejection reason of the specified `promise`.
911+
912+
Example:
913+
914+
```js
915+
const fn = () => {
916+
throw new TypeError('🦄');
917+
};
918+
919+
test('throws', t => {
920+
const error = t.throws(() => {
921+
fn();
922+
}, TypeError);
923+
924+
t.is(error.message, '🦄');
925+
});
926+
```
927+
928+
```js
929+
const promise = Promise.reject(new TypeError('🦄'));
930+
931+
test('rejects', async t => {
932+
const error = await t.throws(promise);
933+
t.is(error.message, '🦄');
934+
});
935+
```
911936

912937
### `.notThrows(function|promise, [message])`
913938

914-
Assert that `function` doesn't throw an `error` or `promise` resolves.
939+
Assert that `function` does not throw an error or that `promise` does not reject with an error.
915940

916941
### `.regex(contents, regex, [message])`
917942

0 commit comments

Comments
 (0)