Skip to content

Commit 0f6d6a6

Browse files
authored
docs: add sync-only info to expect.toThrowError tip (#7381)
1 parent 970973e commit 0f6d6a6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/api/expect.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,14 @@ You can provide an optional argument to test that a specific error is thrown:
701701

702702
:::tip
703703
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+
```
704712
:::
705713

706714
For example, if we want to test that `getFruitStock('pineapples')` throws, we could write:

0 commit comments

Comments
 (0)