Wrap in act() to avoid extraneous console.error #134
Merged
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.
I was working through exercise 2-extra 3, and was having a hard time getting the tests to pass, even though my implementation seemed to work fine in the browser, without throwing an error.
I added a
useStateinuseAsyncto track whether or not the fetch should be considered cancelled, and added auseEffectin the component with a cleanup method to call the setter for that state. The test failed on the last step, and when I replaced thealfredTipwith a plainexpect(console.error).not.toHaveBeenCalled()I could see this console error:Wrapping an
act()around the click and the unmount removes the warning and lets the test pass. This PR also wraps thetype, just because that feels cleaner for some reason.I know my solution wasn't the same as what KCD shows in the video (and it's not as good), but he did leave the instructions vague on purpose, so it seems like the tests should accept anything that works. 😉