From 1216358794c39adc2275f8133e157b20e1434c29 Mon Sep 17 00:00:00 2001 From: sanjeev40 Date: Sun, 1 May 2022 17:32:55 +0530 Subject: [PATCH] Add swr infinite test with Object type argument --- test/use-swr-infinite.test.tsx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/use-swr-infinite.test.tsx b/test/use-swr-infinite.test.tsx index 183909ccde..91d1db3cbe 100644 --- a/test/use-swr-infinite.test.tsx +++ b/test/use-swr-infinite.test.tsx @@ -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 ( + <> +
data: {String(data)}
+ + + ) + } + + renderWithConfig() + await screen.findByText('data: foo-0') + + fireEvent.click(screen.getByText('mutate')) + expect(fetcher).toBeCalledTimes(1) + + expect(logger).toEqual([undefined, ['foo-0']]) + }) })