Skip to content

TypeError: (0 , _reactTestRenderer.act) is not a function #831

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

Closed
cksal0805 opened this issue Apr 28, 2022 · 4 comments
Closed

TypeError: (0 , _reactTestRenderer.act) is not a function #831

cksal0805 opened this issue Apr 28, 2022 · 4 comments
Labels
question Further information is requested

Comments

@cksal0805
Copy link

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 function
@cksal0805 cksal0805 added the bug Something isn't working label Apr 28, 2022
@mpeyper
Copy link
Member

mpeyper commented Apr 28, 2022

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.

@joshuaellis joshuaellis added question Further information is requested and removed bug Something isn't working labels Apr 28, 2022
@cksal0805
Copy link
Author

@mpeyper Thanks. but, my react version is 17 😿

@mpeyper
Copy link
Member

mpeyper commented Apr 29, 2022

Then your react-test-renderer version should match your react version.

@cksal0805
Copy link
Author

@mpeyper oh, thanks! 🥳🥳🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants