Skip to content

Commit

Permalink
Add swr infinite test for revalidation with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjeev40 committed May 1, 2022
1 parent 9aa2373 commit 9660485
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/use-swr-infinite.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ describe('useSWRInfinite', () => {
await screen.findByText('data: B1,B2,B3')
})

it('should revalidate when the component is mounted and revalidateOnMount is enabled', async () => {
it('should revalidate the resource with bound mutate when arguments are passed', async () => {
const key = createKey()

let counter = 0
Expand Down Expand Up @@ -1220,4 +1220,37 @@ describe('useSWRInfinite', () => {
fireEvent.click(screen.getByText('mutate'))
await screen.findByText('data: 2')
})

// https://github.com/vercel/swr/issues/1899
it('should revalidate the resource with bound mutate when arguments are passed', async () => {
let t = 0
const key = createKey()
const fetcher = jest.fn(async () =>
createResponse(`foo-${t++}`, { delay: 10 })
)
const logger = []
function Page() {
const { data, mutate } = useSWRInfinite(() => key, fetcher, {
dedupingInterval: 0
})
logger.push(data)
return (
<>
<div>data: {String(data)}</div>
<button onClick={() => mutate(data, { revalidate: true })}>
mutate
</button>
</>
)
}

renderWithConfig(<Page />)
await screen.findByText('data: foo-0')

fireEvent.click(screen.getByText('mutate'))
await screen.findByText('data: foo-1')
expect(fetcher).toBeCalledTimes(2)

expect(logger).toEqual([undefined, ['foo-0'], ['foo-1']])
})
})

0 comments on commit 9660485

Please sign in to comment.