-
-
Notifications
You must be signed in to change notification settings - Fork 311
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
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.
Mikastark, rmckeel, Maximaximum and Killerbear
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed