@@ -939,8 +939,33 @@ describe('Result', () => {
939939 const it = result [ Symbol . asyncIterator ] ( )
940940 await it . next ( )
941941 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
942- const { value , done } = await it . return ! ( summary )
942+ const summaryPromise = it . return ! ( summary )
943943
944+ streamObserverMock . onCompleted ( { } )
945+
946+ const { value, done } = await summaryPromise
947+ expect ( value ) . toBe ( summary )
948+ expect ( done ) . toEqual ( true )
949+ } )
950+
951+ it ( 'should return resultant summary when it get called without params' , async ( ) => {
952+ const keys = [ 'a' , 'b' ]
953+ const rawRecord1 = [ 1 , 2 ]
954+ const rawRecord2 = [ 3 , 4 ]
955+ const summary = new ResultSummary ( 'query' , { } , { } )
956+
957+ streamObserverMock . onKeys ( keys )
958+ streamObserverMock . onNext ( rawRecord1 )
959+ streamObserverMock . onNext ( rawRecord2 )
960+
961+ const it = result [ Symbol . asyncIterator ] ( )
962+ await it . next ( )
963+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
964+ const summaryPromise = it . return ! ( )
965+
966+ streamObserverMock . onCompleted ( { } )
967+
968+ const { value, done } = await summaryPromise
944969 expect ( value ) . toEqual ( summary )
945970 expect ( done ) . toEqual ( true )
946971 } )
@@ -953,6 +978,7 @@ describe('Result', () => {
953978 streamObserverMock . onKeys ( keys )
954979 streamObserverMock . onNext ( rawRecord1 )
955980 streamObserverMock . onNext ( rawRecord2 )
981+ streamObserverMock . onCompleted ( { } )
956982
957983 const it = result [ Symbol . asyncIterator ] ( )
958984
@@ -966,8 +992,9 @@ describe('Result', () => {
966992 expect ( done ) . toEqual ( true )
967993 } )
968994
969- it ( 'should not subscribe to the observer when it is the first api called' , async ( ) => {
995+ it ( 'should subscribe to the observer when it is the first api called' , async ( ) => {
970996 const subscribe = jest . spyOn ( streamObserverMock , 'subscribe' )
997+ streamObserverMock . onCompleted ( { } )
971998
972999 const it = result [ Symbol . asyncIterator ] ( )
9731000
@@ -976,11 +1003,12 @@ describe('Result', () => {
9761003
9771004 await it . next ( )
9781005
979- expect ( subscribe ) . not . toBeCalled ( )
1006+ expect ( subscribe ) . toBeCalled ( )
9801007 } )
9811008
9821009 it ( 'should not canceld stream when it is the first api called' , async ( ) => {
9831010 const cancel = jest . spyOn ( streamObserverMock , 'cancel' )
1011+ streamObserverMock . onCompleted ( { } )
9841012
9851013 const it = result [ Symbol . asyncIterator ] ( )
9861014
@@ -1001,6 +1029,7 @@ describe('Result', () => {
10011029 streamObserverMock . onKeys ( keys )
10021030 streamObserverMock . onNext ( rawRecord1 )
10031031 streamObserverMock . onNext ( rawRecord2 )
1032+ streamObserverMock . onCompleted ( { } )
10041033
10051034 const it = result [ Symbol . asyncIterator ] ( )
10061035
@@ -1013,26 +1042,28 @@ describe('Result', () => {
10131042
10141043 it ( 'should prevent following next requests to subscribe to the stream' , async ( ) => {
10151044 const subscribe = jest . spyOn ( streamObserverMock , 'subscribe' )
1045+ streamObserverMock . onCompleted ( { } )
10161046
10171047 const it = result [ Symbol . asyncIterator ] ( )
10181048
10191049 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10201050 await it . return ! ( new ResultSummary ( 'query' , { } , { } ) )
10211051 await it . next ( )
10221052
1023- expect ( subscribe ) . not . toBeCalled ( )
1053+ expect ( subscribe ) . toBeCalledTimes ( 1 )
10241054 } )
10251055
10261056 it ( 'should prevent following peek requests to subscribe to the stream' , async ( ) => {
10271057 const subscribe = jest . spyOn ( streamObserverMock , 'subscribe' )
1058+ streamObserverMock . onCompleted ( { } )
10281059
10291060 const it = result [ Symbol . asyncIterator ] ( )
10301061
10311062 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10321063 await it . return ! ( new ResultSummary ( 'query' , { } , { } ) )
10331064 await it . peek ( )
10341065
1035- expect ( subscribe ) . not . toBeCalled ( )
1066+ expect ( subscribe ) . toBeCalledTimes ( 1 )
10361067 } )
10371068 } )
10381069
0 commit comments