File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
src/packages/switch/__test__ Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react'
22import { render , fireEvent , waitFor , act } from '@testing-library/react'
33import '@testing-library/jest-dom'
4+ import { Loading1 } from '@nutui/icons-react'
45import { Switch } from '../switch'
56
67test ( '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} )
You can’t perform that action at this time.
0 commit comments