We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
expect.toThrowError
1 parent 970973e commit 0f6d6a6Copy full SHA for 0f6d6a6
docs/api/expect.md
@@ -701,6 +701,14 @@ You can provide an optional argument to test that a specific error is thrown:
701
702
:::tip
703
You must wrap the code in a function, otherwise the error will not be caught, and test will fail.
704
+
705
+This does not apply for async calls as [rejects](#rejects) correctly unwraps the promise:
706
+```ts
707
+test('expect rejects toThrow', async ({ expect }) => {
708
+ const promise = Promise.reject(new Error('Test'))
709
+ await expect(promise).rejects.toThrowError()
710
+})
711
+```
712
:::
713
714
For example, if we want to test that `getFruitStock('pineapples')` throws, we could write:
0 commit comments