@@ -609,8 +609,37 @@ describe('useSWRInfinite', () => {
609
609
await screen . findByText ( 'data:local-mutation' )
610
610
} )
611
611
612
+ it ( 'should mutate a cache with getInfiniteKey based on a current data' , async ( ) => {
613
+ const getKey = index => [ `pagetest-13` , index ]
614
+ function Comp ( ) {
615
+ const { data, size, setSize } = useSWRInfinite < string , string > (
616
+ getKey ,
617
+ ( _ , index ) => createResponse ( `page ${ index } , ` )
618
+ )
619
+ useEffect ( ( ) => {
620
+ setSize ( size + 1 )
621
+ // eslint-disable-next-line react-hooks/exhaustive-deps
622
+ } , [ ] )
623
+ return < div > data:{ data } </ div >
624
+ }
625
+
626
+ render ( < Comp /> )
627
+
628
+ screen . getByText ( 'data:' )
629
+ await screen . findByText ( 'data:page 0, page 1,' )
630
+
631
+ await act ( ( ) =>
632
+ mutate (
633
+ getInfiniteKey ( getKey ) ,
634
+ data => data . map ( value => `(edited)${ value } ` ) ,
635
+ false
636
+ )
637
+ )
638
+ await screen . findByText ( 'data:(edited)page 0, (edited)page 1,' )
639
+ } )
640
+
612
641
it ( 'should be able to use getInfiniteKey with a custom cache' , async ( ) => {
613
- const key = 'page-test-13 ;'
642
+ const key = 'page-test-14 ;'
614
643
const customCache1 = new Map ( [ [ key , 'initial-cache' ] ] )
615
644
const { cache, mutate : mutateCustomCache } = createCache ( customCache1 )
616
645
function Page ( ) {
0 commit comments