Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions docs/src/api/class-genericassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ const value = 1;
expect(value).not.toBe(2);
```

## property: GenericAssertions.resolves
* since: v1.9
- returns: <[GenericAssertions]>

Use `resolves` to unwrap the value of a fulfilled promise so any other matcher can be chained. If the promise is rejected the assertion fails.

For example, this code tests that the promise resolves and that the resulting value is `'lemon'`:

```js
test('resolves to lemon', async () => {
await expect(Promise.resolve('lemon')).resolves.toBe('lemon');
});
```

## property: GenericAssertions.rejects
* since: v1.9
- returns: <[GenericAssertions]>

Use `.rejects` to unwrap the reason of a rejected promise so any other matcher can be chained. If the promise is fulfilled the assertion fails.

For example, this code tests that the promise rejects with reason `'octopus'`:

```js
test('rejects to octopus', async () => {
await expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus');
});
```


## method: GenericAssertions.toBe
* since: v1.9
Expand Down
28 changes: 28 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7915,6 +7915,34 @@ interface GenericAssertions<R> {
*
*/
not: GenericAssertions<R>;
/**
* Use `resolves` to unwrap the value of a fulfilled promise so any other matcher can be chained. If the promise is
* rejected the assertion fails.
*
* For example, this code tests that the promise resolves and that the resulting value is `'lemon'`:
*
* ```js
* test('resolves to lemon', async () => {
* await expect(Promise.resolve('lemon')).resolves.toBe('lemon');
* });
* ```
*
*/
resolves: GenericAssertions<R>;
/**
* Use `.rejects` to unwrap the reason of a rejected promise so any other matcher can be chained. If the promise is
* fulfilled the assertion fails.
*
* For example, this code tests that the promise rejects with reason `'octopus'`:
*
* ```js
* test('rejects to octopus', async () => {
* await expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus');
* });
* ```
*
*/
rejects: GenericAssertions<R>;
/**
* Compares value with
* [`expected`](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-be-option-expected) by
Expand Down
2 changes: 2 additions & 0 deletions utils/generate_types/overrides-test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ interface AsymmetricMatchers {

interface GenericAssertions<R> {
not: GenericAssertions<R>;
resolves: GenericAssertions<R>;
rejects: GenericAssertions<R>;
toBe(expected: unknown): R;
toBeCloseTo(expected: number, numDigits?: number): R;
toBeDefined(): R;
Expand Down
Loading