Skip to content

Commit

Permalink
test: fix some failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awmleer committed May 30, 2022
1 parent e813593 commit 062ae05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/components/dialog/tests/dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
waitFor,
waitForElementToBeRemoved,
sleep,
actSleep,
} from 'testing'
import Dialog, { DialogAlertProps } from '..'
import { act } from '@testing-library/react'
Expand Down Expand Up @@ -164,15 +165,17 @@ describe('Dialog', () => {

const { getByText, getAllByText } = await render(<Confirm />)
fireEvent.click(getByText('btn'))
await act(async () => {
await fireEvent.click(getAllByText('确定')[0])
act(() => {
fireEvent.click(getAllByText('确定')[0])
})
await actSleep(100)
expect(fn.mock.calls[0][0]).toBe(true)

fireEvent.click(getByText('btn'))
await act(async () => {
await fireEvent.click(getAllByText('取消')[1])
act(() => {
fireEvent.click(getAllByText('取消')[1])
})
await actSleep(100)
expect(fn.mock.calls[1][0]).toBe(false)
})

Expand Down
12 changes: 7 additions & 5 deletions src/components/modal/tests/modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,18 @@ describe('Modal', () => {

const { getByText, getAllByText } = await render(<Confirm />)
fireEvent.click(getByText('btn'))
await act(async () => {
await fireEvent.click(getAllByText('确定')[0])
await actSleep(100)
act(() => {
fireEvent.click(getAllByText('确定')[0])
})
expect(fn.mock.calls[0][0]).toBe(true)

await actSleep(100)
fireEvent.click(getByText('btn'))
await actSleep(100)
act(() => {
fireEvent.click(getAllByText('取消')[1])
fireEvent.click(getAllByText('取消')[0])
})
await actSleep(100)
expect(fn.mock.calls[0][0]).toBe(true)
expect(fn.mock.calls[1][0]).toBe(false)
})

Expand Down

0 comments on commit 062ae05

Please sign in to comment.