You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assert that `function` throws an error, or `promise` rejects with an error.
916
+
Assert that `function` throws an error, `promise` rejects with an error, or `function` returns a rejected `promise`.
917
917
918
918
`error` can be an error constructor, error message, regex matched against the error message, or validation function.
919
919
@@ -952,9 +952,21 @@ test('rejects', async t => {
952
952
});
953
953
```
954
954
955
+
When testing an asynchronous function you must also wait for the assertion to complete:
956
+
957
+
```js
958
+
test('throws', asynct=> {
959
+
consterror=awaitt.throws(async () => {
960
+
thrownewTypeError('🦄');
961
+
}, TypeError);
962
+
963
+
t.is(error.message, '🦄');
964
+
});
965
+
```
966
+
955
967
### `.notThrows(function|promise, [message])`
956
968
957
-
Assert that `function` does not throw an error or that `promise` does not reject with an error.
969
+
Assert that `function` does not throw an error, `promise` does not reject with an error, or `function` returns a promise that does not reject with an error.
958
970
959
971
Like the `.throws()` assertion, when testing a promise you must wait for the assertion to complete:
0 commit comments