Skip to content

Commit

Permalink
test: fix all act warnings (#2031)
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 authored Jun 16, 2022
1 parent 9263ca7 commit 8f0288b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
20 changes: 5 additions & 15 deletions test/use-swr-infinite.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -941,22 +941,15 @@ describe('useSWRInfinite', () => {
})

// https://github.com/vercel/swr/issues/908
//TODO: This test trigger act warning
it('should revalidate first page after mutating', async () => {
let renderedData
const key = createKey()
let v = 'old'

function Page() {
const {
data,
size,
mutate: boundMutate
} = useSWRInfinite(
const { data, mutate: boundMutate } = useSWRInfinite(
i => [key, i],
() => v
() => createResponse(v)
)
renderedData = data

return (
<div>
Expand All @@ -968,19 +961,16 @@ describe('useSWRInfinite', () => {
>
mutate
</button>
<p>size=${size}</p>
<p>data:{data}</p>
</div>
)
}

renderWithConfig(<Page />)

await screen.findByText('mutate')
await nextTick()
expect(renderedData).toEqual(['old'])
await screen.findByText('data:old')
fireEvent.click(screen.getByText('mutate'))
await nextTick()
expect(renderedData).toEqual(['new'])
await screen.findByText('data:new')
})

it('should reuse cached value for new pages', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/use-swr-local-mutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1122,13 +1122,13 @@ describe('useSWR - local mutation', () => {

renderWithConfig(<Page />)

await sleep(20)
await act(() => sleep(20))
await executeWithoutBatching(() =>
mutate(createResponse('end', { delay: 50 }), {
optimisticData: 'start'
})
)
await sleep(20)
await act(() => sleep(20))

// There can never be any changes during a mutation — it should be atomic.
expect(renderedData.indexOf('end') - renderedData.indexOf('start')).toEqual(
Expand Down

0 comments on commit 8f0288b

Please sign in to comment.