chore(test): replace deprecated `initEvent` (#8490)

This commit is contained in:
zqran 2023-07-11 17:38:32 +08:00 committed by GitHub
parent 7c2e44ff5f
commit 736cf154cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -6,8 +6,10 @@ function triggerEvent(
event: string,
process?: (e: any) => any
) {
const e = document.createEvent('HTMLEvents')
e.initEvent(event, true, true)
const e = new Event(event, {
bubbles: true,
cancelable: true
})
if (event === 'click') {
;(e as any).button = 0
}

View File

@ -3,8 +3,10 @@ export function triggerEvent(
event: string,
process?: (e: any) => any
) {
const e = document.createEvent('HTMLEvents')
e.initEvent(event, true, true)
const e = new Event(event, {
bubbles: true,
cancelable: true
})
if (process) process(e)
target.dispatchEvent(e)
return e