Skip to content

Commit

Permalink
Add swr infinite test with Object type argument
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjeev40 committed May 1, 2022
1 parent 13360eb commit 1216358
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/use-swr-infinite.test.tsx
Expand Up @@ -1253,4 +1253,36 @@ describe('useSWRInfinite', () => {

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

// https://github.com/vercel/swr/issues/1899
it('should not revalidate the resource with bound mutate when options is of Object type', 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: false })}>
mutate
</button>
</>
)
}

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

fireEvent.click(screen.getByText('mutate'))
expect(fetcher).toBeCalledTimes(1)

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

0 comments on commit 1216358

Please sign in to comment.