The Do’s and Don’ts of Testing Apollo in React

Unit testing versus Integration testing

Do not mock individual functions 🚫

Do mock at the service worker level ✅
  • We don’t have to mock any files, libraries or functions. i.e. More of our code gets tested!
  • We can test the Apollo configuration that could impact the output such as caching or type policies
  • Our tests are no longer coupled to Apollo — We could swap out our fetching library or use fetch() directly

Do not define another client for tests 🚫

Do not hard code your mocks 🚫

Do rely on the GraphQL type system ✅

Do Test Driven Development ✅





Tech Lead at Payble. Sydney, Australia. We’re hiring

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

Recommended from Medium

Nowhere to somewhere

Typescript Enums and Polymorphism with Type Matching

Creating a Confirm Dialog in React and Tailwind CSS

Building a Generic Enterprise Application Integration Pipeline

About Expo EAS Build

Building Games for the Terminal with React

Inventing Games. Game Loop in JavaScript.

React 17.0 — The news is that there is no news

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
Adam Hannigan

Adam Hannigan

Tech Lead at Payble. Sydney, Australia. We’re hiring

More from Medium

A Quick Guide To Choosing A Robust Frontend Tech Stack

Server side pagination in AG React Data Grid Community Edition

Cypress and GraphQL

React Testing Library — My Notes #1