@@ -58,7 +58,16 @@ describe('Infinite queries', () => {
5858 lastPageParam ,
5959 allPageParams ,
6060 ) => lastPageParam + 1 ,
61+ getPreviousPageParam : (
62+ firstPage ,
63+ allPages ,
64+ firstPageParam ,
65+ allPageParams ,
66+ ) => {
67+ return firstPageParam > 0 ? firstPageParam - 1 : undefined
68+ } ,
6169 } ,
70+
6271 // Actual query arg type should be `number`
6372 query ( pageParam ) {
6473 return `https://example.com/listItems?page=${ pageParam } `
@@ -110,6 +119,21 @@ describe('Infinite queries', () => {
110119 ] )
111120 }
112121
122+ const entry1PrevPageMissing = await storeRef . store . dispatch (
123+ pokemonApi . endpoints . getInfinitePokemon . initiate ( 'fire' , {
124+ direction : 'backward' ,
125+ } ) ,
126+ )
127+
128+ if ( entry1PrevPageMissing . status === QueryStatus . fulfilled ) {
129+ // There is no p
130+ expect ( entry1PrevPageMissing . data . pages ) . toEqual ( [
131+ // two pages, one entry each
132+ [ { id : '0' , name : 'Pokemon 0' } ] ,
133+ [ { id : '1' , name : 'Pokemon 1' } ] ,
134+ ] )
135+ }
136+
113137 // console.log(
114138 // 'API state: ',
115139 // util.inspect(storeRef.store.getState().api, { depth: Infinity }),
@@ -141,5 +165,20 @@ describe('Infinite queries', () => {
141165 [ { id : '4' , name : 'Pokemon 4' } ] ,
142166 ] )
143167 }
168+
169+ const entry2PrevPage = await storeRef . store . dispatch (
170+ pokemonApi . endpoints . getInfinitePokemon . initiate ( 'water' , {
171+ direction : 'backward' ,
172+ } ) ,
173+ )
174+
175+ if ( entry2PrevPage . status === QueryStatus . fulfilled ) {
176+ expect ( entry2PrevPage . data . pages ) . toEqual ( [
177+ // three pages, one entry each
178+ [ { id : '2' , name : 'Pokemon 2' } ] ,
179+ [ { id : '3' , name : 'Pokemon 3' } ] ,
180+ [ { id : '4' , name : 'Pokemon 4' } ] ,
181+ ] )
182+ }
144183 } )
145184} )
0 commit comments