From 68db1bdb0dbb6c3e658091fc328b20cb86bb90f3 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Wed, 24 Apr 2024 09:38:11 -0400 Subject: [PATCH] add msw vs createschemafetch faq section --- docs/source/development-testing/schema-driven-testing.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/source/development-testing/schema-driven-testing.mdx b/docs/source/development-testing/schema-driven-testing.mdx index 63b37468f62..465ed89b92c 100644 --- a/docs/source/development-testing/schema-driven-testing.mdx +++ b/docs/source/development-testing/schema-driven-testing.mdx @@ -284,6 +284,12 @@ describe("Products", () => { ### FAQ +#### When should I use `createSchemaFetch` vs [MSW](https://mswjs.io/)? + +There are many benefits to using [MSW](https://mswjs.io/): it's a powerful tool with a great set of APIs. Read more about its philosophy and benefits [here](https://mswjs.io/blog/why-mock-service-worker/). + +Wherever possible, use MSW: it enables more realistic tests that can catch more bugs by intercepting requests _after_ they've been dispatched by an application. MSW also supports both REST and GraphQL handlers, so if your application uses a combination (e.g. to fetch data from a third party endpoint), MSW will provide more flexibility than `createSchemaFetch`, which is a more lightweight solution. + #### Should I share a single `ApolloClient` instance between tests? No; please create a new instance of `ApolloClient` for each test. Even if the cache is reset in between tests, the client maintains some internal state that is not reset. This could have some unintended consequences. For example, the `ApolloClient` instance could have pending queries that could cause the following test's queries to be deduplicated by default.