element-plus/packages/test-utils/make-scroll.ts

12 lines
407 B
TypeScript
Raw Normal View History

2020-09-02 17:44:14 +08:00
import { sleep } from '@element-plus/test-utils'
const makeScroll = async (dom: Element, name: 'scrollTop' | 'scrollLeft', offset: number) => {
2020-09-07 16:48:11 +08:00
const eventTarget = dom === document.documentElement ? window : dom
2020-09-02 17:44:14 +08:00
dom[name] = offset
2020-09-07 16:48:11 +08:00
eventTarget.dispatchEvent(new CustomEvent('scroll'))
2020-09-02 17:44:14 +08:00
// must use setTimeout instead of nextTick to wait dom change
return await sleep()
}
export default makeScroll