Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use "mockResolvedValue" instead"
  • Loading branch information
danawoodman committed Mar 1, 2018
commit 0f374a5b22d3fad78f50fdf23e6a8253aa601b4d
2 changes: 1 addition & 1 deletion docs/MockFunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jest.mock('axios');

test('should fetch users', () => {
const resp = {data: [{name: 'Bob'}]};
axios.get.mockReturnValue(Promise.resolve(resp));
axios.get.mockResolvedValue(resp);

Choose a reason for hiding this comment

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

@danawoodman, documentation should have been changed too (e.g. mockReturnValue vs mockResolvedValue):

Once we mock the module we can provide a mockReturnValue for .get that returns the data we want our test to assert against. In effect, we are saying that we want axios.get('/users.json') to return a fake response.

I've noticed it because create-react-app uses Jest 20 which doesn't have mockResolvedValue yet.

Copy link
Member

Choose a reason for hiding this comment

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

@DamianFekete fwiw, create-react-app is on Jest 22 and these docs are for Jest 22

Copy link

@DamianFekete DamianFekete Mar 15, 2018

Choose a reason for hiding this comment

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

@rickhanlonii, the released version of create-react-app, 1.5.2, still uses [[email protected]].
The next branch (1.5.1 😄) uses Jest 22.

I do appreciate your comment 👍!

Copy link
Member

Choose a reason for hiding this comment

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

Ah, good to know


// or you could use the follwing depending on your use case:
// axios.get.mockImpementation(() => Promise.resolve(resp))
Expand Down