Replies: 1 comment 13 replies
-
I think you should just mock the actual network request or fetch-function that is happening, not the whole react-query module. Here is how you can test a custom hook with react-query:
|
Beta Was this translation helpful? Give feedback.
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm going crazy finding a solution for this one even though I would guess it's a pretty common use.
I have a custom react-query hook that accesses the currently logged in user in my application like this:
And then I try to test it mocking the entire module react-query first and then the implementation of useQuery so I can control what it returns (can't think of a more standard way than doing just that).
However it seems like this is not the right way to mock an NPM module because I get an error message: _reactQuery.useQuery.mockImplementation is not a function.
I am asking because it seems to me like this should be a pretty basic functionality that most users would like to test but is is not covered in the examples in the documentation. Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions