Example setup for Preact + Jest + Enzyme + React Query #3752
Replies: 3 comments 7 replies
-
Have you set up Providing a reproduction repo would help a lot. |
Beta Was this translation helpful? Give feedback.
-
I was starting with just trying to get the unmocked query working first and was then just going to mock the axios.get so that the test was using as much of the real application code as possible. Sounds like that might not be that simple though. I'm a newbie to testing React components (obviously!), so am trying to figure out the best practices for setting this up so that I can test an app as comprehensively as possible. Do you have any recommendations or pointers to some full examples of testing an application with API calls via React Query? Some pointers on how/where to implement the mocking would be super helpful. |
Beta Was this translation helpful? Give feedback.
-
This worked great once I had mocked my API calls. Thanks for all your help. |
Beta Was this translation helpful? Give feedback.
-
I am struggling to get testing working with Jest + Enzyme + React Query as the test generates the following error from within the QueryClientProvider of React Query:
TypeError: Cannot read properties of null (reading 'useEffect')
I have tried using a super-simple test case like this and still get the error:
When I test my own Preact component with a useEffect call from preact/hooks, then it works fine, so I assume it is something in my config that is not wired up correctly for non-Preact modules that use React hooks.
Is there a good example of how to configure testing with Preact + Jest + Enzyme + React Query?
Beta Was this translation helpful? Give feedback.
All reactions