1
1
import React , { useEffect , useState } from 'react'
2
2
import { render , fireEvent , act , screen } from '@testing-library/react'
3
3
import { mutate , createCache , SWRConfig } from 'swr'
4
- import useSWRInfinite , { serialize } from 'swr/infinite'
4
+ import useSWRInfinite , { unstable_serialize } from 'swr/infinite'
5
5
import { sleep , createKey , createResponse } from './utils'
6
6
7
7
describe ( 'useSWRInfinite' , ( ) => {
@@ -581,7 +581,7 @@ describe('useSWRInfinite', () => {
581
581
await screen . findByText ( 'data:' )
582
582
} )
583
583
584
- it ( 'should mutate a cache with `serialize `' , async ( ) => {
584
+ it ( 'should mutate a cache with `unstable_serialize `' , async ( ) => {
585
585
let count = 0
586
586
function Page ( ) {
587
587
const { data } = useSWRInfinite < string , string > (
@@ -596,20 +596,22 @@ describe('useSWRInfinite', () => {
596
596
597
597
await screen . findByText ( 'data:page-test-12-0:1' )
598
598
599
- await act ( ( ) => mutate ( serialize ( index => `page-test-12-${ index } ` ) ) )
599
+ await act ( ( ) =>
600
+ mutate ( unstable_serialize ( index => `page-test-12-${ index } ` ) )
601
+ )
600
602
await screen . findByText ( 'data:page-test-12-0:2' )
601
603
602
604
await act ( ( ) =>
603
605
mutate (
604
- serialize ( index => `page-test-12-${ index } ` ) ,
606
+ unstable_serialize ( index => `page-test-12-${ index } ` ) ,
605
607
'local-mutation' ,
606
608
false
607
609
)
608
610
)
609
611
await screen . findByText ( 'data:local-mutation' )
610
612
} )
611
613
612
- it ( 'should mutate a cache with `serialize ` based on a current data' , async ( ) => {
614
+ it ( 'should mutate a cache with `unstable_serialize ` based on a current data' , async ( ) => {
613
615
const getKey = index => [ `pagetest-13` , index ]
614
616
function Comp ( ) {
615
617
const { data, size, setSize } = useSWRInfinite < string , string > (
@@ -630,15 +632,15 @@ describe('useSWRInfinite', () => {
630
632
631
633
await act ( ( ) =>
632
634
mutate (
633
- serialize ( getKey ) ,
635
+ unstable_serialize ( getKey ) ,
634
636
data => data . map ( value => `(edited)${ value } ` ) ,
635
637
false
636
638
)
637
639
)
638
640
await screen . findByText ( 'data:(edited)page 0, (edited)page 1,' )
639
641
} )
640
642
641
- it ( 'should be able to use `serialize ` with a custom cache' , async ( ) => {
643
+ it ( 'should be able to use `unstable_serialize ` with a custom cache' , async ( ) => {
642
644
const key = 'page-test-14;'
643
645
const customCache1 = new Map ( [ [ key , 'initial-cache' ] ] )
644
646
const { cache, mutate : mutateCustomCache } = createCache ( customCache1 )
@@ -659,11 +661,11 @@ describe('useSWRInfinite', () => {
659
661
660
662
await screen . findByText ( 'data:initial-cache' )
661
663
662
- await act ( ( ) => mutateCustomCache ( serialize ( ( ) => key ) ) )
664
+ await act ( ( ) => mutateCustomCache ( unstable_serialize ( ( ) => key ) ) )
663
665
await screen . findByText ( 'data:response data' )
664
666
665
667
await act ( ( ) =>
666
- mutateCustomCache ( serialize ( ( ) => key ) , 'local-mutation' , false )
668
+ mutateCustomCache ( unstable_serialize ( ( ) => key ) , 'local-mutation' , false )
667
669
)
668
670
await screen . findByText ( 'data:local-mutation' )
669
671
} )
0 commit comments