question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Revisiting Apollo Client's testing approach

See original GitHub issue

We currently recommend using the MockedProvider and associated API approach to testing applications built using Apollo Client. MockedProvider works well in a lot of cases, but can be difficult to manage as codebases increase in complexity due to its very rigid functionality, often unhelpful error messages, and boilerplate heavy nature.

To work around some of the current limitations of Apollo Client’s recommended testing approach, the community has come up with some really interesting and more modern approaches to testing. A small sampling:

To make sure Apollo Client is giving developers the tools they need to develop robust and effective client applications out of the box, we’re working on a new testing approach that will become part of the core library.

We’ll share more details about these plans shortly, but would love to hear from the community regarding their biggest complaints about Apollo Client’s existing testing functionality, what people would like to see fixed or handled differently, and hear about recommendations of community approaches you prefer.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:14
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
jpvajdacommented, Jun 29, 2022

I found Relay’s approach with the MockPayloadGenerator appealing.

One of the patterns you may see in the tests for Relay components: 95% of the test code is the test preparation—the gigantic mock object with dummy data, manually created, or just a copy of a sample server response that needs to be passed as the network response. And the remaining 5% is actual test code. As a result, people don’t test much. It’s hard to create and manage all these dummy payloads for different cases. Hence, writing tests is time-consuming and tests are sometimes painful to maintain.

2reactions
radfahrercommented, Jun 16, 2022

By far the biggest problem with MockedProvider is that it is not composable. It would be convenient to be able to wrap all fixtures with a MockProvider that has mocks for all the default data, and to be able to wrap a specific fixture with an additional MockProvider to override the mocks for just that fixture/test.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Apollo Client Applications - Apollo GraphQL Blog
This article will discuss three different approaches to testing Apollo Client applications: unit, integration, and end-to-end tests.
Read more >
Mock Apollo Client in tests (#68) · Issues - GitLab
Mocking Apollo Client to the rescue​​ Using different handlers, we can check how component renders different responses or errors. Below I'll ...
Read more >
NASA's Orion capsule buzzes the moon in a last step ... - NPR
The close approach of 81 miles occurred as the crew capsule and its three ... has visited the moon since NASA's Apollo program...
Read more >
This Is What Happens When VR Meets the Real World
Range Rover also uses virtual reality in its design process. ... aerodynamics, and crash performance can all be tested in virtual reality without...
Read more >
Writing Tests for Apollo Client in React - Robin Wieruch
But the testing doesn't stop here. Since you have used a spy on the mutate() method of the Apollo Client which result in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found