1
+ import type { QuerySubState } from '@internal/query/core/apiState'
2
+ import type { Post } from '@internal/query/tests/mocks/handlers'
3
+ import { posts } from '@internal/query/tests/mocks/handlers'
4
+ import { actionsReducer , setupApiStore } from '@internal/tests/utils/helpers'
1
5
import type { SerializedError } from '@reduxjs/toolkit'
2
6
import { configureStore } from '@reduxjs/toolkit'
3
7
import type { BaseQueryFn , FetchBaseQueryError } from '@reduxjs/toolkit/query'
4
8
import { createApi , fetchBaseQuery } from '@reduxjs/toolkit/query'
5
- import type { Post } from './mocks/handlers'
6
- import { posts } from './mocks/handlers'
7
- import { actionsReducer , setupApiStore } from '../../tests/utils/helpers'
8
- import type { QuerySubState } from '@reduxjs/toolkit/dist/query/core/apiState'
9
9
10
10
describe ( 'queryFn base implementation tests' , ( ) => {
11
11
const baseQuery : BaseQueryFn < string , { wrappedByBaseQuery : string } , string > =
12
12
vi . fn ( ( arg : string ) =>
13
13
arg . includes ( 'withErrorQuery' )
14
14
? { error : `cut${ arg } ` }
15
- : { data : { wrappedByBaseQuery : arg } }
15
+ : { data : { wrappedByBaseQuery : arg } } ,
16
16
)
17
17
18
18
const api = createApi ( {
@@ -193,27 +193,27 @@ describe('queryFn base implementation tests', () => {
193
193
endpointName . includes ( 'Throw' )
194
194
? `An unhandled error occurred processing a request for the endpoint "${ endpointName } ".
195
195
In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: resultFrom(${ endpointName } )]`
196
- : ''
196
+ : '' ,
197
197
)
198
198
if ( expectedResult === 'data' ) {
199
199
expect ( result ) . toEqual (
200
200
expect . objectContaining ( {
201
201
data : `resultFrom(${ endpointName } )` ,
202
- } )
202
+ } ) ,
203
203
)
204
204
} else if ( expectedResult === 'error' ) {
205
205
expect ( result ) . toEqual (
206
206
expect . objectContaining ( {
207
207
error : `resultFrom(${ endpointName } )` ,
208
- } )
208
+ } ) ,
209
209
)
210
210
} else {
211
211
expect ( result ) . toEqual (
212
212
expect . objectContaining ( {
213
213
error : expect . objectContaining ( {
214
214
message : `resultFrom(${ endpointName } )` ,
215
215
} ) ,
216
- } )
216
+ } ) ,
217
217
)
218
218
}
219
219
} )
@@ -241,28 +241,28 @@ describe('queryFn base implementation tests', () => {
241
241
endpointName . includes ( 'Throw' )
242
242
? `An unhandled error occurred processing a request for the endpoint "${ endpointName } ".
243
243
In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: resultFrom(${ endpointName } )]`
244
- : ''
244
+ : '' ,
245
245
)
246
246
247
247
if ( expectedResult === 'data' ) {
248
248
expect ( result ) . toEqual (
249
249
expect . objectContaining ( {
250
250
data : `resultFrom(${ endpointName } )` ,
251
- } )
251
+ } ) ,
252
252
)
253
253
} else if ( expectedResult === 'error' ) {
254
254
expect ( result ) . toEqual (
255
255
expect . objectContaining ( {
256
256
error : `resultFrom(${ endpointName } )` ,
257
- } )
257
+ } ) ,
258
258
)
259
259
} else {
260
260
expect ( result ) . toEqual (
261
261
expect . objectContaining ( {
262
262
error : expect . objectContaining ( {
263
263
message : `resultFrom(${ endpointName } )` ,
264
264
} ) ,
265
- } )
265
+ } ) ,
266
266
)
267
267
}
268
268
} )
@@ -275,12 +275,12 @@ describe('queryFn base implementation tests', () => {
275
275
result = await store . dispatch ( thunk )
276
276
} ) . toHaveConsoleOutput (
277
277
`An unhandled error occurred processing a request for the endpoint "withNeither".
278
- In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]`
278
+ In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]` ,
279
279
)
280
280
expect ( result ! . error ) . toEqual (
281
281
expect . objectContaining ( {
282
282
message : 'endpointDefinition.queryFn is not a function' ,
283
- } )
283
+ } ) ,
284
284
)
285
285
}
286
286
{
@@ -293,12 +293,12 @@ describe('queryFn base implementation tests', () => {
293
293
result = await store . dispatch ( thunk )
294
294
} ) . toHaveConsoleOutput (
295
295
`An unhandled error occurred processing a request for the endpoint "mutationWithNeither".
296
- In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]`
296
+ In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]` ,
297
297
)
298
298
expect ( ( result as any ) . error ) . toEqual (
299
299
expect . objectContaining ( {
300
300
message : 'endpointDefinition.queryFn is not a function' ,
301
- } )
301
+ } ) ,
302
302
)
303
303
}
304
304
} )
@@ -372,14 +372,14 @@ describe('usage scenario tests', () => {
372
372
373
373
it ( 'can chain multiple queries together' , async ( ) => {
374
374
const result = await storeRef . store . dispatch (
375
- api . endpoints . getRandomUser . initiate ( )
375
+ api . endpoints . getRandomUser . initiate ( ) ,
376
376
)
377
377
expect ( result . data ) . toEqual ( posts [ 1 ] )
378
378
} )
379
379
380
380
it ( 'can wrap a service like Firebase' , async ( ) => {
381
381
const result = await storeRef . store . dispatch (
382
- api . endpoints . getFirebaseUser . initiate ( 1 )
382
+ api . endpoints . getFirebaseUser . initiate ( 1 ) ,
383
383
)
384
384
expect ( result . data ) . toEqual ( mockData )
385
385
} )
@@ -388,7 +388,7 @@ describe('usage scenario tests', () => {
388
388
let result : QuerySubState < any >
389
389
await expect ( async ( ) => {
390
390
result = await storeRef . store . dispatch (
391
- api . endpoints . getMissingFirebaseUser . initiate ( 1 )
391
+ api . endpoints . getMissingFirebaseUser . initiate ( 1 ) ,
392
392
)
393
393
} )
394
394
. toHaveConsoleOutput ( `An unhandled error occurred processing a request for the endpoint "getMissingFirebaseUser".
@@ -399,7 +399,7 @@ describe('usage scenario tests', () => {
399
399
expect . objectContaining ( {
400
400
message : 'Missing user' ,
401
401
name : 'Error' ,
402
- } )
402
+ } ) ,
403
403
)
404
404
} )
405
405
} )
0 commit comments