Skip to content

Commit 3898e64

Browse files
committed
fix refresh interval test
1 parent 1c1b9f2 commit 3898e64

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/use-swr.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,41 +543,41 @@ describe('useSWR - refresh', () => {
543543
return new Promise(res => setTimeout(res, 150))
544544
})
545545
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 2"`)
546+
fireEvent.click(container.firstElementChild)
546547
await act(() => {
547-
fireEvent.click(container.firstElementChild)
548548
// it will clear 200ms timer and setup a new 300ms timer
549549
return new Promise(res => setTimeout(res, 200))
550550
})
551-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 2"`)
551+
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 3"`)
552552
await act(() => {
553553
return new Promise(res => setTimeout(res, 110))
554554
})
555-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 3"`)
555+
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 4"`)
556556
await act(() => {
557557
// wait for new 300ms timer
558558
return new Promise(res => setTimeout(res, 310))
559559
})
560-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 4"`)
560+
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`)
561+
fireEvent.click(container.firstElementChild)
561562
await act(() => {
562-
fireEvent.click(container.firstElementChild)
563563
// it will clear 300ms timer and setup a new 400ms timer
564564
return new Promise(res => setTimeout(res, 300))
565565
})
566-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 4"`)
566+
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 6"`)
567567
await act(() => {
568568
return new Promise(res => setTimeout(res, 110))
569569
})
570-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`)
570+
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 7"`)
571+
fireEvent.click(container.firstElementChild)
571572
await act(() => {
572-
fireEvent.click(container.firstElementChild)
573573
// it will clear 400ms timer and stop
574574
return new Promise(res => setTimeout(res, 110))
575575
})
576-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`)
576+
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 7"`)
577577
await act(() => {
578578
return new Promise(res => setTimeout(res, 110))
579579
})
580-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`)
580+
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 7"`)
581581
})
582582

583583
it('should update data upon interval changes -- changes happened during revalidate', async () => {

0 commit comments

Comments
 (0)