Skip to content

Commit dd433c0

Browse files
vctormbKent C. Dodds
authored and
Kent C. Dodds
committed
docs: reference about the mocks folder (#181)
<!-- What changes are being made? (What feature/bug is being fixed here?) --> **What**: Well, I was struggling to mock the axios response following the main example here. After hours searching it, I've discovered that we can add the __mocks__ folder to mock functions. <!-- Why are these changes necessary? --> **Why**: I've added a small line of comment to reference about the manual-mocks to be more clear and facilitate to the beginners. <!-- How were these changes implemented? --> **How**: I followed the example inside the [jest documentation](https://jestjs.io/docs/en/manual-mocks). <!-- Have you done all of these things? --> **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> - [x] Documentation - [ ] Tests - [x] Ready to be merged - [ ] Added myself to contributors table <!-- feel free to add additional comments --> Kent, I'm new into the testing world and I didn't understand very well why in the doc example was created a __mocks__ folder just to mock the .get function. Why not only use the jest.mock('axios') instead? Thank you!
1 parent fae141a commit dd433c0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ import React from 'react'
8686
import {render, fireEvent, cleanup, waitForElement} from 'react-testing-library'
8787
// this adds custom jest matchers from jest-dom
8888
import 'jest-dom/extend-expect'
89-
import axiosMock from 'axios' // the mock lives in a __mocks__ directory
89+
90+
// the mock lives in a __mocks__ directory
91+
// to know more about manual mocks, access: https://jestjs.io/docs/en/manual-mocks
92+
import axiosMock from 'axios'
9093
import Fetch from '../fetch' // see the tests for a full implementation
9194

9295
// automatically unmount and cleanup DOM after the test is finished.

0 commit comments

Comments
 (0)