@@ -37,6 +37,7 @@ describe('Infinite queries', () => {
3737 }
3838
3939 let counters : Record < string , number > = { }
40+ let queryCounter = 0
4041
4142 const pokemonApi = createApi ( {
4243 baseQuery : fetchBaseQuery ( { baseUrl : 'https://pokeapi.co/api/v2/' } ) ,
@@ -149,6 +150,7 @@ describe('Infinite queries', () => {
149150 const url = new URL ( request . url )
150151 const pageString = url . searchParams . get ( 'page' )
151152 const pageNum = parseInt ( pageString || '0' )
153+ queryCounter ++
152154
153155 const results : Pokemon [ ] = [
154156 { id : `${ pageNum } ` , name : `Pokemon ${ pageNum } ` } ,
@@ -168,6 +170,7 @@ describe('Infinite queries', () => {
168170 counters = { }
169171
170172 hitCounter = 0
173+ queryCounter = 0
171174
172175 process . env . NODE_ENV = 'development'
173176 } )
@@ -697,6 +700,44 @@ describe('Infinite queries', () => {
697700 [ { id : '0' , name : 'Pokemon 0' } ] ,
698701 [ { id : '1' , name : 'Pokemon 1' } ] ,
699702 ] )
703+
704+ expect ( queryCounter ) . toBe ( 2 )
705+
706+ const entry2InitialLoad = await storeRef . store . dispatch (
707+ pokemonApiWithRefetch . endpoints . getInfinitePokemon . initiate ( 'water' , { } ) ,
708+ )
709+
710+ checkResultData ( entry2InitialLoad , [ [ { id : '0' , name : 'Pokemon 0' } ] ] )
711+
712+ expect ( queryCounter ) . toBe ( 3 )
713+
714+ const entry2SecondPage = await storeRef . store . dispatch (
715+ pokemonApiWithRefetch . endpoints . getInfinitePokemon . initiate ( 'water' , {
716+ direction : 'forward' ,
717+ } ) ,
718+ )
719+ checkResultData ( entry2SecondPage , [
720+ [ { id : '0' , name : 'Pokemon 0' } ] ,
721+ [ { id : '1' , name : 'Pokemon 1' } ] ,
722+ ] )
723+
724+ expect ( queryCounter ) . toBe ( 4 )
725+
726+ // Should now be able to switch back to the first query.
727+ // The hooks dispatch on arg change without a direction.
728+ // That should trigger a refetch of the first query, meaning two requests.
729+ // It should also _replace_ the existing results, rather than appending
730+ // duplicate entries ([0, 1, 0, 1])
731+ const entry1Refetched = await storeRef . store . dispatch (
732+ pokemonApiWithRefetch . endpoints . getInfinitePokemon . initiate ( 'fire' , { } ) ,
733+ )
734+
735+ checkResultData ( entry1Refetched , [
736+ [ { id : '0' , name : 'Pokemon 0' } ] ,
737+ [ { id : '1' , name : 'Pokemon 1' } ] ,
738+ ] )
739+
740+ expect ( queryCounter ) . toBe ( 6 )
700741 } )
701742
702743 test ( 'Works with cache manipulation utils' , async ( ) => {
0 commit comments