Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Allow MockedResponse results to be returned from a function #2788

Merged
merged 2 commits into from
Feb 8, 2019

Conversation

hwillson
Copy link
Member

@hwillson hwillson commented Feb 8, 2019

The result property of a MockedResponse is currently restricted to being a pre-configured fixed value. Allowing results to be calculated/returned from a function instead of being pre-configured, opens up new test verification paths, that can be useful when using MockedProvider.

This PR adjusts MockedResponse’s result such that if a function is set for its value, that function will be fired and its result will be passed to the Observable matching the incoming mocked request.

Fixes apollographql/apollo-feature-requests#84.

@hwillson hwillson requested a review from benjamn as a code owner February 8, 2019 16:55
The `result` property of a `MockedResponse` is currently
restricted to being a pre-configured fixed value. Allowing
results to be calculated/returned from a function instead of
being pre-configured, opens up new test verification paths,
that can be useful when using `MockedProvider`.

This commit adjusts `MockedResponse`’s `result` such that if
a function is set for its value, that function will be fired and
its result will be passed to the Observable matching the
incoming mocked `request`.

Fixes apollographql/apollo-feature-requests#84.
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, since FetchResult can never be a function (at least according to the type system).

Co-Authored-By: hwillson <hugh@octonary.com>
@hwillson hwillson merged commit 5325fac into master Feb 8, 2019
@hwillson hwillson deleted the hwillson/fr-84 branch February 8, 2019 17:18
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.

Ability to tell if a mock was called on MockedProvider
2 participants