Skip to content

Commit

Permalink
test: imporve dynamic polling interval test (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
promer94 committed Apr 22, 2020
1 parent 62f98c7 commit 94f1c88
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/use-swr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ describe('useSWR - refresh', () => {
refreshInterval: int,
dedupingInterval: 100
})
return <div onClick={() => setInt(int + 100)}>count: {data}</div>
return (
<div onClick={() => setInt(num => (num < 400 ? num + 100 : 0))}>
count: {data}
</div>
)
}
const { container } = render(<Page />)
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: "`)
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 94f1c88

Please sign in to comment.