I have a simple hook which calls useQuery to get data from a graphql query.
export function useGetUser () {
const { data, refetch, error, loading } = useQuery(GET_USER, {client, fetchPolicy: 'cache-and-network'})
return {data, refetch}
}
Now in my unit tests, I am using react-hooks-testing library and calling the hook like so :
const { result, waitForNextUpdate, rerender } = renderHook(() => useGetUser())
await waitForNextUpdate();
act(() => {
rerender()
})
await waitForNextUpdate();
Now in this case, if I am sure that the data on the backend is changing between the 2 function calls, why don’t I see it as an update in the hook ?
Does calling useQuery not have a 1:1 relation with the actual network calls?
My intuition around this was that on every render, useQuery would reach out to the server and get new data.
In my test, if I do a refetch manually, then I do get the updated results at the end.