If you spy on the useQuery hook, you won't know if there is a correct relationship present between the GraphQL query and the parameters passed to useQuery.

MSW ensures each query/mutation has the corresponding handler for the component. Otherwise, it throws an exception/warning that something is missing.

Also, if there is a contradiction between the variables in GraphQL query and useQuery variables, then the MSW handler will not receive the contradicting variables. It helps to identify that something is wrong with the communication between the GraphQL query and the React component using useQuery.

Mocking useQuery directly does not provide all the confidence that MSW provides.

--

--

--

Fullstack developer at Unite

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aishwaryalakshmi Panneerselvam

Aishwaryalakshmi Panneerselvam

Fullstack developer at Unite

More from Medium

Amiga do fim

What is Dogioh? $DGH explained and made simple

Open Banking at Kroo

HIEA 112 Final Assignment