element-plus/packages/test-utils/make-scroll.ts
三咲智子 b8c38a9fe5
chore: enhance eslint rules (#6476)
* chore: enhance eslint rules

* chore: enhance eslint rules
2022-03-08 14:03:32 +08:00

23 lines
477 B
TypeScript

import sleep from './sleep'
const makeScroll = (
dom: Element,
name: 'scrollTop' | 'scrollLeft',
offset: number
) => {
const eventTarget = dom === document.documentElement ? window : dom
dom[name] = offset
const evt = new CustomEvent('scroll', {
detail: {
target: {
[name]: offset,
},
},
})
eventTarget.dispatchEvent(evt)
// must use setTimeout instead of nextTick to wait dom change
return sleep()
}
export default makeScroll