Skip to content

Commit

Permalink
fix(react): fixed test code for the Delay component
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 committed Feb 8, 2024
1 parent 2dae595 commit b9348bf
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/react/src/Delay.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { CustomError, TEXT } from '@suspensive/test-utils'
import { render, screen, waitFor } from '@testing-library/react'
import ms from 'ms'
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { Delay } from './Delay'
import { Delay_ms_prop_should_be_greater_than_or_equal_to_0, SuspensiveError } from './models/SuspensiveError'

beforeAll(() => {
beforeEach(() => {
vi.useFakeTimers({ shouldAdvanceTime: true })
})

afterAll(() => {
afterEach(() => {
vi.runOnlyPendingTimers()
vi.useRealTimers()
})

Expand All @@ -35,12 +36,9 @@ describe('<Delay/>', () => {
{TEXT}
</Delay>
)

vi.advanceTimersByTime(ms('0.5s'))

expect(screen.queryByRole('paragraph')).toBeInTheDocument()

vi.advanceTimersByTime(ms('0.5s'))
vi.advanceTimersByTime(ms('1s'))

await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
})
Expand Down

0 comments on commit b9348bf

Please sign in to comment.