-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Mounted wrapper was not wrapped in act(...) warning still showing #2153
Comments
enzyme now wraps the things it knows about in |
I am testing a custom hook above that uses await act(async () => {
await flushPromises();
}); but I get this error:
|
indeed, Can you share the code of |
This issue is actually due to The solution that worked for me was upgrading both import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { flushPromises, renderHook, HOOK_WRAPPER_ID } from 'utils/tests';
import useData from './use-data';
const mockURL = 'https://example.com';
const mockConfig = {
data: ':dataHere',
};
describe('useData', () => {
it('fetches data config', async () => {
fetch.mockResponseOnce(JSON.stringify(mockConfig));
const wrapper = mount(renderHook(() => useData(mockURL)));
// now act supports async/await syntax
await act(async () => {
await flushPromises();
});
wrapper.update();
const dataConfig = wrapper.find(`#${HOOK_WRAPPER_ID}`).props().hook;
expect(dataConfig).toEqual(mockConfig);
});
}); @ljharb Thanks for your help and patience troubleshooting this 😃 |
Current behavior
I have a component that makes use of the useEffect hook to make an asynchronous call an api (or in the test case a mock of a call to an api) and then call the setState hook with the result.
I've written tests that assert on the outcome of the effect (ie content being returned from the api). I'm using v1.14.0 of the adapter for react-16 my tests pass, snapshots are created and everything appears to be working well, however, a warning is repeatedly logged out from react-dom.
Here's the test in question:
Here's the warning:
#2073 claims to have fixed this, but even after upgrading both
enzyme
andenzyme-adapter-react-16
I still encounter this warning.Expected behavior
For no warning to be issued.
API
Version
Adapter
The text was updated successfully, but these errors were encountered: