the-guild-org / the-guild-org/apollo-angular
Not able to flush multiple times to test subscriptions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 309
- Avg merge
- 1h 45m
- Merged PRs (30d)
- 3
Description
I'm not able to test a component which uses a subscription to receive updates because it's not possible to call flush(...) multiple times on a TestOperation. The contained observer is completed after calling flush for the first time.
Here's an example of a failing test showing this behavior.
it('should receive updates', (done) => {
TestBed.configureTestingModule({
imports: [ApolloTestingModule],
});
const apollo = TestBed.inject(Apollo);
const controller = TestBed.inject(ApolloTestingController);
const query = gql`
subscription dates {
date
}`;
const data1 = {date: '1970-01-01'};
const data2 = {date: '1970-01-02'};
let resultData: any;
apollo.subscribe<any>({query: query}).subscribe({
next: (result) => {
resultData = result.data;
},
error: (e) => {
done.fail(e);
},
});
const op = controller.expectOne(query);
op.flush({data: data1});
op.flush({data: data2});
expect(resultData).toEqual(data2);
done();
});
An additional argument keepOpen: bool (with default false) or an additional function like flushAndKeepOpen(...), omitting the call to complete(), could solve this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with TestOperation and ApolloTestingController.expectOne in the failing subscription test shown in the issue. Reproduce the two flush(...) calls and inspect when the contained observer completes. Done means a subscription can receive both updates through repeated flush calls while preserving the existing single-flush behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, graphql, typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100