-
Notifications
You must be signed in to change notification settings - Fork 726
docs: replace "axiosMock" with "msw" in React Testing Library example #483
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f977452
docs: replace "axiosMock" with "msw" in React Testing Library example
kettanaito 51a31d3
docs: remove snapshot testing in "React Example"
kettanaito 46415a2
docs: add a recommendation block for msw
kettanaito e007d84
docs: explain API mocking in "React Example"
kettanaito 62ab238
docs: add error handling scenario to "React Example"
kettanaito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add an
afterEach(() => server.resetHandlers())
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a safe option—yes, but unless you declare runtime handlers via
server.use()
there’s nothing to reset. I’d not suggest callingresetHandlers
by default. Developers that need it will find it :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point. Now that you mention it, I think the
server.use
call should be inside the test rather than outside it. That's what people should be doing most of the time.With that in mind, resetHandlers should be included.
And I think it should be used by default 😉
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I please double check on this?
I see your point of using
resetHandlers
andserver.use
inside a test suite, but I think I'm confused about what runtime handler to addvia server.use
, as the example tests exactly one API communication to "GET /greeting".Am I missing something in this? 🤔 Do you suggest to move
rest.get('/greeting')
fromsetupServer
toserver.use
inside a test suite?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fair point. There are two things to consider:
With that in mind, I think we should adjust this example so we have two tests. One for the success case, and one for the error case. That way the first one can rely on the default handlers and one that can add a runtime handler for the error.
Because I see using
afterEach(() => server.resetHandlers())
as an important default whenever someone usesserver.use
and we should probably demonstrate that so people don't add a bunch of complicated single-test-specific handlers to theirsetupServer
call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is perfect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the error handling test scenario to this example.
useState
touseReducer
infetch.js
to reflect the error and data relation.server.use()
with permanent override there.afterEach
that callsserver.resetHanders()
.Please, could you double check if that
fetch.js
looks okay to you? Thanks.