-
Notifications
You must be signed in to change notification settings - Fork 276
Description
Describe the bug
When updating to new version, all tests having act will fail
Expected behavior
update documentation with new way of using act or declare it as breaking change
Steps to Reproduce
import { PropsWithChildren, ReactElement } from 'react';
import { NavigationContext } from '@react-navigation/native';
import { act } from 'react-test-renderer';
import { fireEvent, navContext, render } from 'test-utils';
import { CloseButton } from 'src/Features/Authentication/EmailSent/SubComponents/CloseButton/CloseButton';
import { routeNames } from 'src/Shared/Constants';
const TestComponent = ({ children }: PropsWithChildren): ReactElement => (
<NavigationContext.Provider value={navContext}>{children}</NavigationContext.Provider>
);
describe('CloseButton component', () => {
it('on press navigates to login screen', () => {
const { getByTestId } = render(, { wrapper: TestComponent });
const button = getByTestId('CloseButton');
act(() => {
fireEvent.press(button);
});
expect(navContext.navigate).toHaveBeenCalledTimes(1);
expect(navContext.navigate).toHaveBeenLastCalledWith(routeNames.Login);
});
});
report
● CloseButton component › on press navigates to login screen
Trying to detect host component names triggered the following error:
Can't access .root on unmounted test renderer
There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.
Please check if you are using compatible versions of React Native and React Native Testing Library.
20 |
21 | act(() => {
> 22 | fireEvent.press(button);
| ^
23 | });
24 |
25 | expect(navContext.navigate).toHaveBeenCalledTimes(1);
Screenshots
Versions
"@testing-library/react-native": "11.5.1",