Skip to content

Commit

Permalink
Use mocks to test full result in failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Dec 5, 2024
1 parent 21ee3e0 commit 2d3f8da
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/core/__tests__/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3637,12 +3637,6 @@ test("handles changing variables in rapid succession before other request is com
});

test("does not return partial cache data when `returnPartialData` is false and new variables are passed in", async () => {
const cache = new InMemoryCache();
const client = new ApolloClient({
cache,
link: ApolloLink.empty(),
});

const partialQuery = gql`
query MyCar($id: ID) {
car(id: $id) {
Expand All @@ -3662,6 +3656,21 @@ test("does not return partial cache data when `returnPartialData` is false and n
}
`;

const cache = new InMemoryCache();
const client = new ApolloClient({
cache,
link: new MockLink([
{
request: { query, variables: { id: 2 } },
result: {
data: {
car: { __typename: "Car", id: 2, make: "Ford", model: "Bronco" },
},
},
},
]),
});

cache.writeQuery({
query: partialQuery,
variables: { id: 1 },
Expand Down Expand Up @@ -3712,4 +3721,10 @@ test("does not return partial cache data when `returnPartialData` is false and n
networkStatus: NetworkStatus.setVariables,
data: undefined,
});

expect(await stream.takeNext()).toEqual({
loading: false,
networkStatus: NetworkStatus.ready,
data: { __typename: "Car", id: 1, make: "Ford", model: "Pinto" },
});
});

0 comments on commit 2d3f8da

Please sign in to comment.