An update to Dropzone inside a test was not wrapped in act(...).
See original GitHub issueWhat is the current behavior?
When trying to test a component containing Dropzone
, there’s a console.errror (but tests pass):
console.error node_modules/react-dom/cjs/react-dom.development.js:506
Warning: An update to Dropzone inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
in Dropzone (at InputFile.js:86)
in div (at InputFile.js:85)
in InputFile (at InputFile.test.js:68)
Test example which triggers the error:
import { render, act } from '@testing-library/react';
describe('InputFile', () => {
it('example', async () => {
act(() => {
const rendered = render(<InputFile {...props} />);
});
});
});
InputFile is:
class InputFile extends React.Component {
onDrop = () => { /*…*/ }
render() {
return (
<Dropzone
onDrop={this.onDrop}
>
{({ getRootProps, getInputProps }) => {
if (uploading) {
return <div>...uploading</div>;
}
return (
<div {...getRootProps()}>
<input {...getInputProps()} />
</div>
);
}}
</Dropzone>
);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9
Top Results From Across the Web
Fix the "not wrapped in act(...)" warning - Kent C. Dodds
There are a few reasons you're getting this warning. Here's how you fix it.
Read more >Jest + react-testing-library: Warning update was not wrapped ...
I was getting this warning: Warning: An update to Formik inside a test was not wrapped in act(...)
Read more >React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. Very happy about the upgrade. But I start to see test errors like this: In...
Read more >Fix Warning in React: Update was not wrapped in act()
To solve this problem we can use waitFor from @testing-library/react . This will wait for whatever is inside it to be true or...
Read more >Fix the "not wrapped in act(...)" warning when testing Custom ...
Any time your test interacts with a React component in a way that results in a state update, you need to make sure...
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
@alex-polunochev it works without await the
Promise
. So you don’t need to have asetTimeout
.I was testing the file upload event and got the same error, the plain component test rendering was fine.
Fixed the problem with input change by creating a Promise with short timeout: