how to test a react component that invokes refetch #5365
Unanswered
Exponent500
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Hi 👋 Try to think about what is important to the user. It sounds like you could test this by using something like Mock Service Worker and mocking two different responses. You can then make assertions about what the component displays before and after the refetch. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Yup I'll see what code snippets I can share that aren't sensitive since this is company code. |
Beta Was this translation helpful? Give feedback.
0 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.
-
Hey there,
I am using this library in a project at work and we have a component that uses useQuery, which will invoke the refetch() function when a refresh button is clicked.
In my unit tests I'd like to verify that a re-fetch occurs by checking that our loading screen is shown, however since our loading screen is only shown if isFetching is true this fails. This is because after the initial fetch sets isFetching to false, it stays false even after calling refetch.
I've only seen examples of how to test this scenario when testing the custom hook that wraps useQuery, but I don't want to test the hook, I want to test the component that is ingesting it.
Beta Was this translation helpful? Give feedback.
All reactions