@@ -14,7 +14,7 @@ beforeEach(() => baseQuery.mockReset())
1414const api = createApi ( {
1515 baseQuery : ( ...args : any [ ] ) => {
1616 const result = baseQuery ( ...args )
17- if ( 'then' in result )
17+ if ( typeof result === 'object' && 'then' in result )
1818 return result
1919 . then ( ( data : any ) => ( { data, meta : 'meta' } ) )
2020 . catch ( ( e : any ) => ( { error : e } ) )
@@ -131,11 +131,16 @@ describe('basic lifecycle', () => {
131131
132132describe ( 'updateQueryData' , ( ) => {
133133 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 )
139144 const { result } = renderHook ( ( ) => api . endpoints . post . useQuery ( '3' ) , {
140145 wrapper : storeRef . wrapper ,
141146 } )
@@ -180,11 +185,14 @@ describe('updateQueryData', () => {
180185 } )
181186
182187 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+
188196 const { result } = renderHook ( ( ) => api . endpoints . post . useQuery ( '3' ) , {
189197 wrapper : storeRef . wrapper ,
190198 } )
@@ -234,6 +242,7 @@ describe('full integration', () => {
234242 title : 'Meanwhile, this changed server-side.' ,
235243 contents : 'Delicious cheese!' ,
236244 } )
245+ . mockResolvedValueOnce ( 42 )
237246 const { result } = renderHook (
238247 ( ) => ( {
239248 query : api . endpoints . post . useQuery ( '3' ) ,
@@ -283,6 +292,7 @@ describe('full integration', () => {
283292 title : 'Meanwhile, this changed server-side.' ,
284293 contents : 'TODO' ,
285294 } )
295+ . mockResolvedValueOnce ( 42 )
286296
287297 const { result } = renderHook (
288298 ( ) => ( {
0 commit comments