Skip to content

Commit a5b0f57

Browse files
committed
feat: update test
1 parent 6f4a65e commit a5b0f57

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/packages/switch/__test__/switch.spec.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react'
22
import { render, fireEvent, waitFor, act } from '@testing-library/react'
33
import '@testing-library/jest-dom'
4+
import { Loading1 } from '@nutui/icons-react'
45
import { Switch } from '../switch'
56

67
test('activeText && checked && onChange && inactiveText && className && style test', async () => {
@@ -49,8 +50,32 @@ test('activeText && checked && onChange && inactiveText && className && style te
4950
}
5051
})
5152

52-
test('disabled test', () => {
53-
render(<Switch disabled />)
53+
test('disabled test', async () => {
54+
const { container } = render(<Switch disabled />)
5455
const el = document.getElementsByClassName('nut-switch-disabled')
5556
expect(el.length > 0).toBe(true)
57+
const buttonEl: Element | null = container.querySelector('.nut-switch-button')
58+
if (buttonEl) {
59+
await act(() => {
60+
fireEvent.click(buttonEl)
61+
})
62+
}
63+
})
64+
65+
test('loadingIcon test', async () => {
66+
const testFn = vi.fn()
67+
const { container } = render(
68+
<Switch loadingIcon={<Loading1 />} onChange={testFn} />
69+
)
70+
const el: Element | null = container.querySelector('.nut-switch-button')
71+
if (el) {
72+
await act(() => {
73+
fireEvent.click(el)
74+
})
75+
waitFor(() => {
76+
// 异步
77+
const el = document.getElementsByClassName('.nut-icon')
78+
expect(el.length > 0).toBe(true)
79+
})
80+
}
5681
})

0 commit comments

Comments
 (0)