mirror of
https://github.com/zhigang1992/react.git
synced 2026-03-26 22:42:51 +08:00
test(utils): add helper function for wrapper update
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
import { act } from 'react-dom/test-utils'
|
||||
import { ReactWrapper } from 'enzyme'
|
||||
|
||||
export const sleep = (time: number) => {
|
||||
return new Promise(resolve => setTimeout(resolve, time))
|
||||
}
|
||||
|
||||
export const updateWrapper = async (wrapper: ReactWrapper, time: number = 0) => {
|
||||
await act(async () => {
|
||||
await sleep(time)
|
||||
wrapper.update()
|
||||
})
|
||||
}
|
||||
|
||||
export const mockNativeEvent = (fn: Function = () => {}) => ({
|
||||
nativeEvent: { stopImmediatePropagation: fn }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user