MSW doesn't provide the means to assert the fetchPolicy
of your GraphQL client because that property is specific to the said client. To my best knowledge, the fetchPolicy
from Apollo doesn't directly translate to any Request properties. It remains an implementation detail of the GraphQL client and controls how it manages re-fetches internally.
I highly recommend against testing the fetchPolicy
for two reasons:
- This is an implementation detail of your request client. This also means that folks at Apollo have tested it rather well so you wouldn't have to.
- It is also your app's implementation detail. The user of your software doesn't even know if you're using Apollo or a specific
fetchPolicy
set in there. Neither should your tests.
Now, that doesn't mean not testing the behavior bound to that property. To correctly test it, run your application in the actual browser and perform user-based operations that would illustrate a particular fetchPolicy
value in action (e.g. that the cached data is displayed first and than is re-fetched). Forget about fetch policies and request clients, focus on what behavior the user would see.