How to fix Apollo’s MockedProvider returning empty objects for fragments

If you’re like me, you burned your wheels a little too long trying to figure out why your mocked data was empty in your React unit tests.

In my case, I had a query like this:

query GetSomething($somethingId: UUID!) {
something(somethingId: $somethingId) {
...something
things {
...thing
}
}
}…

--

--

--

Staff front end engineer | Tech lead | Architect | charlesstover.com

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

Recommended from Medium

Install Vue.js in Laravel 8 application (Jetstream/Livewire Stack) on Macos

Show Calendar — Part 1: Setting Up the API

How to Connect your React App to a REST API

JavaScript ‘for Loops’

Deploying Angular App On GitHub Pages

What’s New in JSCharting v3.3

DOM Manipulation And Examples

Master RxJs: Short-hand value selector

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
Charles Stover

Charles Stover

Staff front end engineer | Tech lead | Architect | charlesstover.com

More from Medium

Setup React and Webpack manually

Exploring Socket.IO in a React Working Environment

Socket.IO communicates between the client and the server.

Resolving Create React App’s “Uncaught ReferenceError: process is not defined”

Getting started with a PureScript React project