Skip to content

Commit 5367fb7

Browse files
committed
add test
1 parent 7326f5d commit 5367fb7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/core/__tests__/ObservableQuery.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6408,6 +6408,49 @@ test('completes open subscription when "stop" is called', async () => {
64086408
expect(observable.hasObservers()).toBe(false);
64096409
});
64106410

6411+
test('accepts new subscribers after "stop" is called', async () => {
6412+
const link = new MockSubscriptionLink();
6413+
const client = new ApolloClient({
6414+
cache: new InMemoryCache(),
6415+
link,
6416+
});
6417+
const query = gql`
6418+
query {
6419+
greeting
6420+
}
6421+
`;
6422+
const observable = client.watchQuery({ query });
6423+
const stream = new ObservableStream(observable);
6424+
const firstOperation = link.operation;
6425+
expect(firstOperation).toBeDefined();
6426+
await expect(stream).toEmitTypedValue({
6427+
data: undefined,
6428+
dataState: "empty",
6429+
loading: true,
6430+
networkStatus: NetworkStatus.loading,
6431+
partial: true,
6432+
});
6433+
6434+
expect(observable.hasObservers()).toBe(true);
6435+
observable.stop();
6436+
await expect(stream).toComplete();
6437+
expect(observable.hasObservers()).toBe(false);
6438+
6439+
const stream2 = new ObservableStream(observable);
6440+
const secondOperation = link.operation;
6441+
expect(secondOperation).toBeDefined();
6442+
expect(secondOperation).not.toBe(firstOperation);
6443+
await expect(stream2).toEmitTypedValue({
6444+
data: undefined,
6445+
dataState: "empty",
6446+
loading: true,
6447+
networkStatus: NetworkStatus.loading,
6448+
partial: true,
6449+
});
6450+
6451+
expect(observable.hasObservers()).toBe(true);
6452+
});
6453+
64116454
test('completes open subscription when "client.stop" is called', async () => {
64126455
const link = new MockSubscriptionLink();
64136456
const client = new ApolloClient({

0 commit comments

Comments
 (0)