@@ -8,8 +8,11 @@ import {
88 waitFor ,
99 act ,
1010} from '@testing-library/react'
11+ import { vi } from 'vitest'
1112
1213describe ( 'fixedCacheKey' , ( ) => {
14+ const onNewCacheEntry = vi . fn ( )
15+
1316 const api = createApi ( {
1417 async baseQuery ( arg : string | Promise < string > ) {
1518 return { data : await arg }
@@ -354,4 +357,34 @@ describe('fixedCacheKey', () => {
354357 expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
355358 expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( 'this should be visible' )
356359 } )
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+ } )
357390} )
0 commit comments