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

Add mock return matchers #5879

Merged
merged 12 commits into from
May 4, 2018
16 changes: 16 additions & 0 deletions docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,22 @@ test('drinkEach drinks each drink', () => {
});
```

### `.toHaveReturned(value)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should doc every new matcher, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: still needs docs

Oh, ignore me then :D


Also under the alias: `.toReturn(value)`

If you have a mock function, you can use `.toHaveReturned` to test that the spy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call it "spy"?

returned a value. For example, let's say you have a mock `drink` that returns
`true`. You can write:

```js
test('drinks returns true', () => {
const drink = jest.fn(() => true);
drink();
expect(drink).toHaveReturned(true);
});
```

### `.toBeCloseTo(number, numDigits)`

Using exact equality with floating point numbers is a bad idea. Rounding means
Expand Down
Loading