Skip to content

Commit 65324e7

Browse files
sukvvondai-shi
andauthored
test(optimization): switch to fake timers, replace 'waitFor' with 'vi.waitFor' (#1120)
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
1 parent 42d99d1 commit 65324e7

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

tests/optimization.test.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { useState } from 'react'
2-
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
3-
import { expect, it, vi } from 'vitest'
2+
import { fireEvent, render, screen } from '@testing-library/react'
3+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
44
import { proxy, useSnapshot } from 'valtio'
55

6+
beforeEach(() => {
7+
vi.useRealTimers()
8+
})
9+
10+
afterEach(() => {
11+
vi.useRealTimers()
12+
})
13+
614
it('regression: useSnapshot renders should not fail consistency check with extra render (nested useSnapshot)', async () => {
715
const obj = proxy({ childCount: 0, parentCount: 0 })
816

@@ -33,7 +41,7 @@ it('regression: useSnapshot renders should not fail consistency check with extra
3341

3442
render(<Parent />)
3543

36-
await waitFor(() => {
44+
await vi.waitFor(() => {
3745
expect(screen.getByText('childCount: 0')).toBeInTheDocument()
3846
expect(screen.getByText('parentCount: 0')).toBeInTheDocument()
3947
})
@@ -45,7 +53,7 @@ it('regression: useSnapshot renders should not fail consistency check with extra
4553

4654
obj.parentCount += 1
4755

48-
await waitFor(() => {
56+
await vi.waitFor(() => {
4957
expect(screen.getByText('childCount: 0')).toBeInTheDocument()
5058
expect(screen.getByText('parentCount: 1')).toBeInTheDocument()
5159
})
@@ -90,7 +98,7 @@ it('regression: useSnapshot renders should not fail consistency check with extra
9098

9199
render(<Parent />)
92100

93-
await waitFor(() => {
101+
await vi.waitFor(() => {
94102
expect(screen.getByText('childCount: 0')).toBeInTheDocument()
95103
expect(screen.getByText('parentCount: 0')).toBeInTheDocument()
96104
})
@@ -104,7 +112,7 @@ it('regression: useSnapshot renders should not fail consistency check with extra
104112

105113
fireEvent.click(screen.getByText('parentButton'))
106114

107-
await waitFor(() => {
115+
await vi.waitFor(() => {
108116
expect(screen.getByText('childCount: 0')).toBeInTheDocument()
109117
expect(screen.getByText('parentCount: 1')).toBeInTheDocument()
110118
})

0 commit comments

Comments
 (0)