Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed broken example in the docs. #4788

Merged
merged 1 commit into from
Oct 30, 2017
Merged
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
15 changes: 5 additions & 10 deletions docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,20 @@ test('resolves to lemon', async () => {

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 a reason:
For example, this code tests that the promise rejects with reason `'octopus'`:

```js
test('fetchData() rejects to be error', () => {
test('rejects to octopus', () => {
// make sure to add a return statement
return expect(Promise.reject('octopus')).rejects.toBeDefined();
return expect(Promise.reject('octopus')).rejects.toBe('octopus');
});
```

Alternatively, you can use `async/await` in combination with `.rejects`.
Moreover, this code tests that the returned reason includes 'octopus'`:

```js
test('fetchData() rejects to be error', async () => {
const drinkOctopus = new Promise(() => {
throw new DisgustingFlavorError('yuck, octopus flavor');
});

await expect(drinkOctopus).rejects.toMatch('octopus');
test('rejects to octopus', async () => {
await expect(Promise.reject('octopus')).rejects.toBe('octopus');
});
```

Expand Down