diff --git a/test/use-swr.test.tsx b/test/use-swr.test.tsx index dee86cb9b..a9b9545f3 100644 --- a/test/use-swr.test.tsx +++ b/test/use-swr.test.tsx @@ -420,7 +420,11 @@ describe('useSWR - refresh', () => { refreshInterval: int, dedupingInterval: 100 }) - return
setInt(int + 100)}>count: {data}
+ return ( +
setInt(num => (num < 400 ? num + 100 : 0))}> + count: {data} +
+ ) } const { container } = render() expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: "`) @@ -464,6 +468,16 @@ describe('useSWR - refresh', () => { return new Promise(res => setTimeout(res, 110)) }) expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`) + await act(() => { + fireEvent.click(container.firstElementChild) + // it will clear 400ms timer and stop + return new Promise(res => setTimeout(res, 110)) + }) + expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`) + await act(() => { + return new Promise(res => setTimeout(res, 110)) + }) + expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`) }) it('should allow use custom isEqual method', async () => {