File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
packages/toolkit/src/query/tests Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -431,6 +431,47 @@ describe('fetchBaseQuery', () => {
431
431
432
432
expect ( request . headers [ 'content-type' ] ) . toBe ( 'application/vnd.api+json' )
433
433
} )
434
+
435
+ it ( 'supports a custom jsonReplacer' , async ( ) => {
436
+ const body = {
437
+ items : new Set ( [ "A" , "B" , "C" ] )
438
+ }
439
+
440
+ let request : any
441
+ ; ( { data : request } = await baseQuery (
442
+ {
443
+ url : '/echo' ,
444
+ body,
445
+ method : 'POST' ,
446
+ } ,
447
+ commonBaseQueryApi ,
448
+ { }
449
+ ) )
450
+
451
+ expect ( request . headers [ 'content-type' ] ) . toBe ( 'application/json' )
452
+ expect ( request . body ) . toEqual ( { items : { } } ) // Set is not properly marshalled by default
453
+
454
+ // Use jsonReplacer
455
+ const baseQueryWithReplacer = fetchBaseQuery ( {
456
+ baseUrl,
457
+ fetchFn : fetchFn as any ,
458
+ jsonReplacer : ( key , value ) => value instanceof Set ? [ ...value ] : value
459
+ } )
460
+
461
+ ; ( { data : request } = await baseQueryWithReplacer (
462
+ {
463
+ url : '/echo' ,
464
+ body,
465
+ method : 'POST' ,
466
+ } ,
467
+ commonBaseQueryApi ,
468
+ { }
469
+ ) )
470
+
471
+ expect ( request . headers [ 'content-type' ] ) . toBe ( 'application/json' )
472
+ expect ( request . body ) . toEqual ( { items : [ "A" , "B" , "C" ] } ) // Set is marshalled correctly by jsonReplacer
473
+
474
+ } )
434
475
} )
435
476
436
477
describe ( 'arg.params' , ( ) => {
You can’t perform that action at this time.
0 commit comments