@@ -14,7 +14,7 @@ beforeEach(() => baseQuery.mockReset())
14
14
const api = createApi ( {
15
15
baseQuery : ( ...args : any [ ] ) => {
16
16
const result = baseQuery ( ...args )
17
- if ( 'then' in result )
17
+ if ( typeof result === 'object' && 'then' in result )
18
18
return result
19
19
. then ( ( data : any ) => ( { data, meta : 'meta' } ) )
20
20
. catch ( ( e : any ) => ( { error : e } ) )
@@ -131,11 +131,16 @@ describe('basic lifecycle', () => {
131
131
132
132
describe ( 'updateQueryData' , ( ) => {
133
133
test ( 'updates cache values, can apply inverse patch' , async ( ) => {
134
- baseQuery . mockResolvedValueOnce ( {
135
- id : '3' ,
136
- title : 'All about cheese.' ,
137
- contents : 'TODO' ,
138
- } )
134
+ baseQuery
135
+ . mockResolvedValueOnce ( {
136
+ id : '3' ,
137
+ title : 'All about cheese.' ,
138
+ contents : 'TODO' ,
139
+ } )
140
+ // TODO I have no idea why the query is getting called multiple times,
141
+ // but passing an additional mocked value (_any_ value)
142
+ // seems to silence some annoying "got an undefined result" logging
143
+ . mockResolvedValueOnce ( 42 )
139
144
const { result } = renderHook ( ( ) => api . endpoints . post . useQuery ( '3' ) , {
140
145
wrapper : storeRef . wrapper ,
141
146
} )
@@ -180,11 +185,14 @@ describe('updateQueryData', () => {
180
185
} )
181
186
182
187
test ( 'does not update non-existing values' , async ( ) => {
183
- baseQuery . mockResolvedValueOnce ( {
184
- id : '3' ,
185
- title : 'All about cheese.' ,
186
- contents : 'TODO' ,
187
- } )
188
+ baseQuery
189
+ . mockImplementationOnce ( async ( ) => ( {
190
+ id : '3' ,
191
+ title : 'All about cheese.' ,
192
+ contents : 'TODO' ,
193
+ } ) )
194
+ . mockResolvedValueOnce ( 42 )
195
+
188
196
const { result } = renderHook ( ( ) => api . endpoints . post . useQuery ( '3' ) , {
189
197
wrapper : storeRef . wrapper ,
190
198
} )
@@ -234,6 +242,7 @@ describe('full integration', () => {
234
242
title : 'Meanwhile, this changed server-side.' ,
235
243
contents : 'Delicious cheese!' ,
236
244
} )
245
+ . mockResolvedValueOnce ( 42 )
237
246
const { result } = renderHook (
238
247
( ) => ( {
239
248
query : api . endpoints . post . useQuery ( '3' ) ,
@@ -283,6 +292,7 @@ describe('full integration', () => {
283
292
title : 'Meanwhile, this changed server-side.' ,
284
293
contents : 'TODO' ,
285
294
} )
295
+ . mockResolvedValueOnce ( 42 )
286
296
287
297
const { result } = renderHook (
288
298
( ) => ( {
0 commit comments