11import gql from "graphql-tag" ;
2- import waitFor from "wait-for-observables" ;
32
43import { ApolloLink } from "../../core/ApolloLink" ;
54import { execute } from "../../core/execute" ;
65import { Observable } from "../../../utilities/observables/Observable" ;
76import { fromError } from "../../utils/fromError" ;
87import { RetryLink } from "../retryLink" ;
8+ import { ObservableStream } from "../../../testing/internal" ;
99
1010const query = gql `
1111 {
@@ -23,9 +23,10 @@ describe("RetryLink", () => {
2323 const retry = new RetryLink ( { delay : { initial : 1 } , attempts : { max } } ) ;
2424 const stub = jest . fn ( ( ) => fromError ( standardError ) ) as any ;
2525 const link = ApolloLink . from ( [ retry , stub ] ) ;
26+ const stream = new ObservableStream ( execute ( link , { query } ) ) ;
27+
28+ await expect ( stream ) . toEmitError ( standardError , { timeout : 1000 } ) ;
2629
27- const [ { error } ] = ( await waitFor ( execute ( link , { query } ) ) ) as any ;
28- expect ( error ) . toEqual ( standardError ) ;
2930 expect ( stub ) . toHaveBeenCalledTimes ( max ) ;
3031 } ) ;
3132
@@ -34,9 +35,11 @@ describe("RetryLink", () => {
3435 const data = { data : { hello : "world" } } ;
3536 const stub = jest . fn ( ( ) => Observable . of ( data ) ) ;
3637 const link = ApolloLink . from ( [ retry , stub ] ) ;
38+ const stream = new ObservableStream ( execute ( link , { query } ) ) ;
39+
40+ await expect ( stream ) . toEmitValue ( data ) ;
41+ await expect ( stream ) . toComplete ( ) ;
3742
38- const [ { values } ] = ( await waitFor ( execute ( link , { query } ) ) ) as any ;
39- expect ( values ) . toEqual ( [ data ] ) ;
4043 expect ( stub ) . toHaveBeenCalledTimes ( 1 ) ;
4144 } ) ;
4245
@@ -50,9 +53,11 @@ describe("RetryLink", () => {
5053 stub . mockReturnValueOnce ( fromError ( standardError ) ) ;
5154 stub . mockReturnValueOnce ( Observable . of ( data ) ) ;
5255 const link = ApolloLink . from ( [ retry , stub ] ) ;
56+ const stream = new ObservableStream ( execute ( link , { query } ) ) ;
57+
58+ await expect ( stream ) . toEmitValue ( data ) ;
59+ await expect ( stream ) . toComplete ( ) ;
5360
54- const [ { values } ] = ( await waitFor ( execute ( link , { query } ) ) ) as any ;
55- expect ( values ) . toEqual ( [ data ] ) ;
5661 expect ( stub ) . toHaveBeenCalledTimes ( 2 ) ;
5762 } ) ;
5863
@@ -129,13 +134,14 @@ describe("RetryLink", () => {
129134 } ) ;
130135 const stub = jest . fn ( ( ) => fromError ( standardError ) ) as any ;
131136 const link = ApolloLink . from ( [ retry , stub ] ) ;
137+ const stream1 = new ObservableStream ( execute ( link , { query } ) ) ;
138+ const stream2 = new ObservableStream ( execute ( link , { query } ) ) ;
139+
140+ await Promise . all ( [
141+ expect ( stream1 ) . toEmitError ( standardError ) ,
142+ expect ( stream2 ) . toEmitError ( standardError ) ,
143+ ] ) ;
132144
133- const [ result1 , result2 ] = ( await waitFor (
134- execute ( link , { query } ) ,
135- execute ( link , { query } )
136- ) ) as any ;
137- expect ( result1 . error ) . toEqual ( standardError ) ;
138- expect ( result2 . error ) . toEqual ( standardError ) ;
139145 expect ( stub ) . toHaveBeenCalledTimes ( 10 ) ;
140146 } ) ;
141147
@@ -144,9 +150,10 @@ describe("RetryLink", () => {
144150 const retry = new RetryLink ( { delay : delayStub , attempts : { max : 3 } } ) ;
145151 const linkStub = jest . fn ( ( ) => fromError ( standardError ) ) as any ;
146152 const link = ApolloLink . from ( [ retry , linkStub ] ) ;
147- const [ { error } ] = ( await waitFor ( execute ( link , { query } ) ) ) as any ;
153+ const stream = new ObservableStream ( execute ( link , { query } ) ) ;
154+
155+ await expect ( stream ) . toEmitError ( standardError ) ;
148156
149- expect ( error ) . toEqual ( standardError ) ;
150157 const operation = ( delayStub . mock . calls [ 0 ] as any ) [ 1 ] ;
151158 expect ( delayStub . mock . calls ) . toEqual ( [
152159 [ 1 , operation , standardError ] ,
@@ -166,9 +173,10 @@ describe("RetryLink", () => {
166173 } ) ;
167174 const linkStub = jest . fn ( ( ) => fromError ( standardError ) ) as any ;
168175 const link = ApolloLink . from ( [ retry , linkStub ] ) ;
169- const [ { error } ] = ( await waitFor ( execute ( link , { query } ) ) ) as any ;
176+ const stream = new ObservableStream ( execute ( link , { query } ) ) ;
177+
178+ await expect ( stream ) . toEmitError ( standardError ) ;
170179
171- expect ( error ) . toEqual ( standardError ) ;
172180 const operation = attemptStub . mock . calls [ 0 ] [ 1 ] ;
173181 expect ( attemptStub . mock . calls ) . toEqual ( [
174182 [ 1 , operation , standardError ] ,
@@ -191,9 +199,10 @@ describe("RetryLink", () => {
191199 ( ) => new Observable ( ( o ) => o . error ( standardError ) )
192200 ) as any ;
193201 const link = ApolloLink . from ( [ retry , linkStub ] ) ;
194- const [ { error } ] = ( await waitFor ( execute ( link , { query } ) ) ) as any ;
202+ const stream = new ObservableStream ( execute ( link , { query } ) ) ;
203+
204+ await expect ( stream ) . toEmitError ( standardError ) ;
195205
196- expect ( error ) . toEqual ( standardError ) ;
197206 const operation = attemptStub . mock . calls [ 0 ] [ 1 ] ;
198207 expect ( attemptStub . mock . calls ) . toEqual ( [
199208 [ 1 , operation , standardError ] ,
0 commit comments