Skip to content

Added jest.mock line remaining in the main example #180

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

Closed
wants to merge 1 commit into from
Closed

Added jest.mock line remaining in the main example #180

wants to merge 1 commit into from

Conversation

vctormb
Copy link
Contributor

@vctormb vctormb commented Sep 18, 2018

What:
Well, I was struggling to mock the axios response following the main example here. After hours searching it, I've discovered that I needed to mock the axios to be able to access the mock functions inside of it.

Why:
I've added a small line of code to not break the example and stop new learners.

How:
I followed the example inside the jest documentation.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Well, I was struggling to mock the axios response following the main example here. After hours searching, I've discovered that I needed to mock the axios to be able to access the mock functions inside of it.

So, I've added a small line of code to not break the example and stop new learners.
@@ -272,34 +276,6 @@ module.exports = {
}
```


#### Export Issue with Babel Versions Lower Than 7
Copy link
Member

Choose a reason for hiding this comment

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

Could you rebase your PR (or just make a new one) that doesn't remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Ok! I'll create another one!

@@ -89,6 +89,10 @@ import 'jest-dom/extend-expect'
import axiosMock from 'axios' // the mock lives in a __mocks__ directory
import Fetch from '../fetch' // see the tests for a full implementation

// Once we mock the module we can provide a mockResolvedValueOnce for .get
// that returns the fake data we want our test to assert against.
jest.mock('axios');
Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessary because the comment on line 89 indicates that there's a mock in the __mocks__ directory.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thanks, but I don't think this change is necessary.

@kentcdodds
Copy link
Member

Would you like to change this PR to add a link to the jest docs about the __mocks__ directory? https://jestjs.io/docs/en/manual-mocks

@vctormb vctormb closed this Sep 18, 2018
julienw pushed a commit to julienw/react-testing-library that referenced this pull request Dec 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants