apollo-client
apollo-client copied to clipboard
Ability to dynamically match mocks
This PR provides the functionality outlined in https://github.com/apollographql/apollo-feature-requests/issues/245
It adds support for a new property MockedResponse.variableMatcher
that is a function that takes variables and returns if they should match for this mock. A user cannot specify both this property as well as response.variables
in the same mock.
It also passes the variables into the ResultFunction
so that a function is able to use them to dynamically build a response. Passing these parameters also allows for the use of a mock for the result function and then asserting that specific variables were passed. This testing strategy results in a cleaner error message for mutations if the correct data is not passed and allows for partial matches using jests "objectContaining" and others.
My team found testing using the MockProvider to be difficult in several situations and these small changes would have greatly improved our ability to test with the ApolloClient.
@prowe: 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/
Are there any additional steps I should take beyond reporting a feature request and opening a PR to have this looked at/discussed. This is my first Pull Request to this project so I may not be following the right process and just want to make sure i'm doing the best I can.
Thanks
Is there any progress on reviewing/merging this? This would greatly help with my needs for mocking in my application.
Thanks for this @prowe - would you or anyone else in the community be interested in rebasing this against main
? This is a great change. We're revisiting our entire testing story (tracked in https://github.com/apollographql/apollo-client/issues/9738) but until that happens, this is definitely an improvement.
Thanks for this @prowe - would you or anyone else in the community be interested in rebasing this against
main
? This is a great change. We're revisiting our entire testing story (tracked in #9738) but until that happens, this is definitely an improvement.
Rebased and should be good. Let me know if there is anything else I can do to be of assistance.
whoa this PR looks great! Can we already start using it ? Do you think it will land in master ?
Thank you !
I think this is a solid PR and would love to get this in our 3.8 release! I've updated the base branch to our release-3.8
branch. I'll take a crack at getting the conflicts resolved.
Hey @prowe! Would you be willing to rebase this against our release-3.8
branch? I've attempted to do this myself, but there are enough changes that I'm afraid I'd butcher your PR in doing so. I'd be happy to get this approved/merged once we are able to get this PR up-to-date and passing tests!
@prowe Think this PR needs another round of rebasing, much appreciated!
It's been two years since I last commented on this and the MR is still open 😢
Is this ever going to be merged? It would be AMAZING!
Thanks for the tap on the shoulder @brycefranzen - we're going to prioritize getting this into our release-3.9
branch and then release it in 3.9.0-alpha.0
for the community to try out, expect that pretty soon. We're looking forward to seeing how folks use this feature and how it will complement the investments we will be making into Apollo Client's testing utilities 🚀
🦋 Changeset detected
Latest commit: de539a099abbaf00e79b24bb1016e5e3b7f77563
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Name | Type |
---|---|
@apollo/client | Minor |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
I attempted to resolve the merge conflicts here. I'll self-review this later in the week and add a changeset file as well.
/release:pr
A new release has been made for this PR. You can install it with npm i @apollo/[email protected]
.
How are things looking here? I see we have a PR release we can use now 🙌🏼 ... Any progress on getting this reviewed/merged so it can be released with v3.9?
How are things looking here? I see we have a PR release we can use now 🙌🏼 ... Any progress on getting this reviewed/merged so it can be released with v3.9?
This is very close to being merged :) Hopefully next week, though I'll be out for a few days at a conference. The final to do item is fixing a TS error these changes have caused that's not being reported on CI since it's occurring in test files (we have a separate to do item to fix that). Thanks for your patience!
This has been released in v3.9.0-alpha.0 🎉