Skip to content

Commit

Permalink
Cover batched XHR cancelling with tests (#1742)
Browse files Browse the repository at this point in the history
This is dependent on apollographql/apollo-client#9248,
so it is not strictly specific to `apollo-angular`, but it seemed important to
ensure that this package does indeed allow to cancel XHR even when batching is
enabled.

Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com>
  • Loading branch information
PowerKiKi and kamilkisiela committed Oct 24, 2022
1 parent 87b0ff3 commit ed70140
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/apollo-angular/http/tests/http-batch-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,4 +723,35 @@ describe('HttpBatchLink', () => {
});
}, 50);
});

test('should cancel XHR when unsubscribing', (done: jest.DoneCallback) => {
const link = httpLink.create({uri: 'graphql', batchMax: 1});
const op = {
query: gql`
query heroes {
heroes {
name
}
}
`,
operationName: 'heroes',
variables: {},
};

execute(link, op)
.subscribe({
next: () => {
done.fail('Should not be here');
},
error: () => {
done.fail('Should not be here');
},
})
.unsubscribe();

setTimeout(() => {
expect(httpBackend.expectOne('graphql').cancelled).toBe(true);
done();
}, 50);
});
});
28 changes: 28 additions & 0 deletions packages/apollo-angular/http/tests/http-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,32 @@ describe('HttpLink', () => {
return true;
});
});

test('should cancel XHR when unsubscribing', () => {
const link = httpLink.create({uri: 'graphql'});
const op = {
query: gql`
query heroes {
heroes {
name
}
}
`,
operationName: 'heroes',
variables: {},
};

execute(link, op)
.subscribe({
next: () => {
throw new Error('Should not be here');
},
error: () => {
throw new Error('Should not be here');
},
})
.unsubscribe();

expect(httpBackend.expectOne('graphql').cancelled).toBe(true);
});
});

0 comments on commit ed70140

Please sign in to comment.