Skip to content

Commit

Permalink
Update tests after restructuring queryManager.mutationStore.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Oct 15, 2020
1 parent ad4be6e commit d53928c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
38 changes: 20 additions & 18 deletions src/__tests__/optimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ describe('optimistic mutation results', () => {
return null;
},
}),
// Enable client.queryManager.mutationStore tracking.
connectToDevTools: true,
});

const obsHandle = client.watchQuery({ query });
Expand Down Expand Up @@ -377,9 +379,9 @@ describe('optimistic mutation results', () => {
);

// @ts-ignore
const latestState = queryManager.mutationStore;
expect(latestState.get('1').loading).toBe(false);
expect(latestState.get('2').loading).toBe(true);
const latestState = queryManager.mutationStore!;
expect(latestState[1].loading).toBe(false);
expect(latestState[2].loading).toBe(true);

return res;
});
Expand All @@ -397,17 +399,17 @@ describe('optimistic mutation results', () => {
);

// @ts-ignore
const latestState = queryManager.mutationStore;
expect(latestState.get('1').loading).toBe(false);
expect(latestState.get('2').loading).toBe(false);
const latestState = queryManager.mutationStore!;
expect(latestState[1].loading).toBe(false);
expect(latestState[2].loading).toBe(false);

return res;
});

// @ts-ignore
const mutationsState = queryManager.mutationStore;
expect(mutationsState.get('1').loading).toBe(true);
expect(mutationsState.get('2').loading).toBe(true);
const mutationsState = queryManager.mutationStore!;
expect(mutationsState[1].loading).toBe(true);
expect(mutationsState[2].loading).toBe(true);

checkBothMutationsAreApplied(
'Optimistically generated',
Expand Down Expand Up @@ -621,9 +623,9 @@ describe('optimistic mutation results', () => {
);

// @ts-ignore
const latestState = client.queryManager.mutationStore;
expect(latestState.get('1').loading).toBe(false);
expect(latestState.get('2').loading).toBe(true);
const latestState = client.queryManager.mutationStore!;
expect(latestState[1].loading).toBe(false);
expect(latestState[2].loading).toBe(true);

return res;
});
Expand All @@ -641,17 +643,17 @@ describe('optimistic mutation results', () => {
);

// @ts-ignore
const latestState = client.queryManager.mutationStore;
expect(latestState.get('1').loading).toBe(false);
expect(latestState.get('2').loading).toBe(false);
const latestState = client.queryManager.mutationStore!;
expect(latestState[1].loading).toBe(false);
expect(latestState[2].loading).toBe(false);

return res;
});

// @ts-ignore
const mutationsState = client.queryManager.mutationStore;
expect(mutationsState.get('1').loading).toBe(true);
expect(mutationsState.get('2').loading).toBe(true);
const mutationsState = client.queryManager.mutationStore!;
expect(mutationsState[1].loading).toBe(true);
expect(mutationsState[2].loading).toBe(true);

checkBothMutationsAreApplied(
'Optimistically generated',
Expand Down
4 changes: 3 additions & 1 deletion src/core/__tests__/QueryManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ describe('QueryManager', () => {
cache: new InMemoryCache({ addTypename: false, ...config }),
clientAwareness,
queryDeduplication,
// Enable client.queryManager.mutationStore tracking.
onBroadcast() {},
});
};

Expand Down Expand Up @@ -3265,7 +3267,7 @@ describe('QueryManager', () => {
queryManager.cache.extract(),
).toEqual({});
expect(queryManager.getQueryStore()).toEqual({});
expect(queryManager.mutationStore.getStore()).toEqual({});
expect(queryManager.mutationStore).toEqual({});

resolve();
});
Expand Down

0 comments on commit d53928c

Please sign in to comment.