@@ -8,8 +8,11 @@ import {
8
8
waitFor ,
9
9
act ,
10
10
} from '@testing-library/react'
11
+ import { vi } from 'vitest'
11
12
12
13
describe ( 'fixedCacheKey' , ( ) => {
14
+ const onNewCacheEntry = vi . fn ( )
15
+
13
16
const api = createApi ( {
14
17
async baseQuery ( arg : string | Promise < string > ) {
15
18
return { data : await arg }
@@ -354,4 +357,34 @@ describe('fixedCacheKey', () => {
354
357
expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
355
358
expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( 'this should be visible' )
356
359
} )
360
+
361
+ test ( 'using fixedCacheKey should create a new cache entry' , async ( ) => {
362
+ api . injectEndpoints ( {
363
+ overrideExisting : true ,
364
+ endpoints : ( build ) => ( {
365
+ send : build . mutation < string , string | Promise < string > > ( {
366
+ query : ( arg ) => arg ,
367
+ onCacheEntryAdded ( arg , { } ) {
368
+ onNewCacheEntry ( arg )
369
+ } ,
370
+ } ) ,
371
+ } ) ,
372
+ } )
373
+
374
+ render ( < Component name = "C1" fixedCacheKey = { "testKey" } /> , {
375
+ wrapper : storeRef . wrapper ,
376
+ } )
377
+
378
+ let c1 = screen . getByTestId ( 'C1' )
379
+
380
+ expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
381
+ expect ( getByTestId ( c1 , 'originalArgs' ) . textContent ) . toBe ( 'undefined' )
382
+
383
+ await act ( async ( ) => {
384
+ getByTestId ( c1 , 'trigger' ) . click ( )
385
+ await Promise . resolve ( )
386
+ } )
387
+
388
+ expect ( onNewCacheEntry ) . toHaveBeenCalledWith ( 'C1' )
389
+ } )
357
390
} )
0 commit comments