TypeError: (0 , _reactTestRenderer.act) is not a function
cksal0805 opened this issue · 4 comments
cksal0805 commented
Hi, I'm having a hard time writing the test code with react-hooks-testing-library.
Can you help me?
I'm sorry for my poor English.
version
- "react-test-renderer": "^18.1.0",
- "@testing-library/jest-dom": "^5.16.4",
- "@testing-library/react-hooks": "^8.0.0",
code
import { QueryClient, QueryClientProvider } from 'react-query';
import { renderHook } from '@testing-library/react-hooks';
import { useGetDataQuery, GetDataQueryType } from 'codegen/generated/graphql';
import graphqlRequestClient from 'utils/graphqlRequestClient';
const queryClient = new QueryClient();
const wrapper = ({ children }: {children: ReactChild}) => (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);
const { result } = renderHook(() => useGetDataQuery<GetDataQueryType>(graphqlRequestClient, {}), {
wrapper
});run
yarn jest myTest
error
TypeError: (0 , _reactTestRenderer.act) is not a functionmpeyper commented
It looks like you are trying to use React 18 (given the version of react-test-renderer. Is that correct?
This package is not going to support React 18 and you should rather import renderHook from the latest version of @testing-library/react. Check out their docs for more details.
mpeyper commented
Then your react-test-renderer version should match your react version.