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