File tree 1 file changed +55
-0
lines changed
packages/query-core/src/__tests__
1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,61 @@ describe('streamedQuery', () => {
74
74
unsubscribe ( )
75
75
} )
76
76
77
+ test ( 'should allow Arrays to be returned from the stream' , async ( ) => {
78
+ const key = queryKey ( )
79
+ const observer = new QueryObserver ( queryClient , {
80
+ queryKey : key ,
81
+ queryFn : streamedQuery ( {
82
+ queryFn : async function * ( ) {
83
+ for await ( const num of createAsyncNumberGenerator ( 3 ) ) {
84
+ yield [ num , num ] as const
85
+ }
86
+ } ,
87
+ } ) ,
88
+ } )
89
+
90
+ const unsubscribe = observer . subscribe ( vi . fn ( ) )
91
+
92
+ expect ( observer . getCurrentResult ( ) ) . toMatchObject ( {
93
+ status : 'pending' ,
94
+ fetchStatus : 'fetching' ,
95
+ data : undefined ,
96
+ } )
97
+
98
+ await vi . advanceTimersByTimeAsync ( 50 )
99
+
100
+ expect ( observer . getCurrentResult ( ) ) . toMatchObject ( {
101
+ status : 'success' ,
102
+ fetchStatus : 'fetching' ,
103
+ data : [ [ 0 , 0 ] ] ,
104
+ } )
105
+
106
+ await vi . advanceTimersByTimeAsync ( 50 )
107
+
108
+ expect ( observer . getCurrentResult ( ) ) . toMatchObject ( {
109
+ status : 'success' ,
110
+ fetchStatus : 'fetching' ,
111
+ data : [
112
+ [ 0 , 0 ] ,
113
+ [ 1 , 1 ] ,
114
+ ] ,
115
+ } )
116
+
117
+ await vi . advanceTimersByTimeAsync ( 50 )
118
+
119
+ expect ( observer . getCurrentResult ( ) ) . toMatchObject ( {
120
+ status : 'success' ,
121
+ fetchStatus : 'idle' ,
122
+ data : [
123
+ [ 0 , 0 ] ,
124
+ [ 1 , 1 ] ,
125
+ [ 2 , 2 ] ,
126
+ ] ,
127
+ } )
128
+
129
+ unsubscribe ( )
130
+ } )
131
+
77
132
test ( 'should replace on refetch' , async ( ) => {
78
133
const key = queryKey ( )
79
134
const observer = new QueryObserver ( queryClient , {
You can’t perform that action at this time.
0 commit comments