Skip to content

Commit

Permalink
Test that mutation awaits promises returned by reobserveQuery.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Mar 11, 2021
1 parent 73c73c7 commit e4c9fad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/__tests__/QueryManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5232,12 +5232,14 @@ describe('QueryManager', () => {
notifyOnNetworkStatusChange: false,
});

let finishedRefetch = false;

return observableToPromise(
{ observable },
result => {
expect(stripSymbols(result.data)).toEqual(data);

queryManager.mutate({
return queryManager.mutate({
mutation,

update(cache) {
Expand All @@ -5252,8 +5254,15 @@ describe('QueryManager', () => {

reobserveQuery(obsQuery) {
expect(obsQuery.options.query).toBe(query);
return obsQuery.refetch();
return obsQuery.refetch().then(async () => {
// Wait a bit to make sure the mutation really awaited the
// refetching of the query.
await new Promise(resolve => setTimeout(resolve, 100));
finishedRefetch = true;
});
},
}).then(() => {
expect(finishedRefetch).toBe(true);
});
},

Expand All @@ -5262,6 +5271,7 @@ describe('QueryManager', () => {
secondReqData,
);
expect(stripSymbols(result.data)).toEqual(secondReqData);
expect(finishedRefetch).toBe(true);
},
).then(resolve, reject);
});
Expand Down

0 comments on commit e4c9fad

Please sign in to comment.