-
Notifications
You must be signed in to change notification settings - Fork 232
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
I have just updated to new versions of react and testing-library and now I see this warning in my hook's test file:
Warning: It looks like you're using the wrong act() around your test interactions.
Be sure to use the matching version of act() corresponding to your renderer:
// for react-dom:
import {act} from 'react-dom/test-utils';
//...
act(() => ...);
// for react-test-renderer:
import TestRenderer from 'react-test-renderer';
const {act} = TestRenderer;
//...
act(() => ...);
in TestHook
in Suspense
Here is code of my test:
import { fireEvent } from '@testing-library/react';
import { renderHook, act } from '@testing-library/react-hooks';
// ...
it('should update return value on hover', () => {
jest.useFakeTimers();
const ref = createRefMock();
const { result } = renderHook(() => useHover(ref));
expect(result.current).toBe(false);
fireEvent.mouseOver(ref.current);
act(() => {
jest.runOnlyPendingTimers();
});
expect(result.current).toBe(true);
fireEvent.mouseOut(ref.current);
expect(result.current).toBe(false);
});
Warning appears on line fireEvent.mouseOut(ref.current);
And if I change it to
act(() => {
fireEvent.mouseOut(ref.current);
});
everything is working fine.
But is still strange that I don't have any problems with fireEvent.mouseOver
.
Do I need to wrap every fireEvent to act in my code?
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested