DEV Community

Discussion on: Testing custom Apollo hooks with React Testing Library

Collapse
 
findlesticks1 profile image
Findlesticks

Thanks for this! From this setup, how would you go about changing the input to the hook and checking the hook's new return values? e.g if you wanted to change queryOptions, but the hook cares about old queries too?

Collapse
 
hugoliconv profile image
Hugo • Edited

I created this hook because I was using the query all over the place and in my case, I know that both the query and the input to the custom hook won't change. The only thing that could change is the queryOptions, maybe I want to change the fetchPolicy option or add a callback when the request is completed using the onCompleted option. But as I said, that is the only thing that could change.

const { loading, error, countries } = useCountries({
  fetchPolicy: "network-only"
});
//...
const { loading, error, countries } = useCountries({
  onCompleted: () => alert("completed")
});