MockedProvider causing test to complain about not using `act()`.
See original GitHub issueIntended outcome:
Actual outcome:
When running test using MockProvider I expect test to not error out with the following error:
Warning: An update to ResearchCategoryList inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
How to reproduce the issue:
The following test will cause test to complain:
it('renders without error', async () => {
let component
act(() => {
component = create(
<MockedProvider mocks={mocks} addTypename={false}>
<ResearchCategoryList category="Education" />
</MockedProvider>
)
})
await wait(0)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
Versions
"@apollo/react-testing": "^3.1.3",
Issue Analytics
- State:
- Created 4 years ago
- Reactions:30
- Comments:26 (2 by maintainers)
Top Results From Across the Web
Testing React components - Apollo GraphQL Docs
The MockedProvider component enables you to define mock responses for individual queries that are executed in your test. This means your test doesn't...
Read more >React Testing Library and the “not wrapped in act” Errors
Case 1: Asynchronous Updates. Test code somehow triggered a testing component to update in an asynchronous way. Here is an example: const MyComponent...
Read more >Debugging Apollo GraphQL MockedProvider - Swarmia
We're big on Apollo GraphQL here at Swarmia, but we've sometimes struggled with mocking. This blog post is here to help!
Read more >Apollo MockedProvider testing issues (my rendered ...
First, the empty array/loading issue was not an issue; I traced everything back to testing-library resetting/re-rendering the component ...
Read more >Unit Testing - React-admin
React-admin relies heavily on unit tests (powered by Jest and ... This will cause seemingly random test failures when you use useStore() in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@donedgardo I’ve beeing having the same issue, using Jest and @testing-library/react. Right now I’m suppressing those warnings, as described in the in the @testing-library/react documentation.
In my jest global setup file, I’ve added
I’m not completely sure about this approach (this might suppress warnings that need to be taken care of), but that does the trick! 😄
@donedgardo Thanks for pointing that issue out. I’ve been using the
wait
exported from@testing-library/react
and that fixes the issue.In your case, I think you can try and wrap the
await wait()
inact
as suggested in this comment.Both solutions work for me! 🎉