Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mockLink.ts #11004

Conversation

cristiancedenogallego
Copy link

@cristiancedenogallego cristiancedenogallego commented Jun 22, 2023

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@apollo-cla
Copy link

@crisys11: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@netlify
Copy link

netlify bot commented Jun 22, 2023

👷 Deploy request for apollo-client-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 9b3fdbd

@changeset-bot
Copy link

changeset-bot bot commented Jun 22, 2023

⚠️ No Changeset found

Latest commit: 9b3fdbd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@alessbell
Copy link
Member

Hi @crisys11 👋 Can you tell us a bit more about what problem this would be solving for you?

Improving our testing utilities is on our tentative 3.9 roadmap, so this is a great time to share any and all feedback on all things Apollo Client testing :) Feel free to drop comments/feedback here or on this pinned issue #9738.

@cristiancedenogallego
Copy link
Author

Hello @alessbell, sometimes we need to re-use mocks, especially when we are working with storybook, so would be great if we can have a configuration params that allow that.

Let me know if i was clear or if you need more details 😄

@alessbell
Copy link
Member

That makes perfect sense, @crisys11 😀

especially when we are working with storybook

How is your team using Storybook with Apollo Client? Are you using this addon, or something custom?

@cristiancedenogallego
Copy link
Author

@alessbell we are using this storybook addon https://storybook.js.org/addons/storybook-addon-apollo-client

We use the MocketProvider
image

and then we pass the mocks to the addon in the story

image

@alessbell
Copy link
Member

TIL there's an Apollo Client Storybook addon, that's neat and very good to know :) Thanks for sharing that info about how you're using it @crisys11! The pain point you're experiencing with MockedProvider is a piece of feedback we've gotten before and one of the main motivations behind improving our testing utilities - we definitely hear you there.

With respect to the approach you've taken with preserveMocks, I appreciate that it's backward-compatible since it's disabled by default, but by giving developers the option to reuse mocks indefinitely in their tests, we'd run into different issues. For example, you couldn't write a test where the same query returns two different results, e.g. where a query succeeds the first time it's run but returns an error on refetch. The first mocked response (success case) would always match if we set preserveMocks to true. (You can see many examples of this if you enable preserveMocks before running Apollo Client's test suite.)

You could toggle this on/off per test, but the way the preserveMocks: true tests would be written would be fundamentally incompatible with the default setting, so you'd essentially be forking your entire test codebase between two different mental models of how mocking works in Apollo Client.

While I recognize there's a genuine need for more flexibility here, I think there's more we can do to give developers flexibility and control in the next phase of Apollo Client testing tools. Subscribe to issue #9738 for updates, we'd love to hear your thoughts/feedback as we begin work in this area.

@alessbell alessbell closed this Jun 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants