composite-click.ts 613 B

12345678910111213141516171819202122232425
  1. import { nextTick } from 'vue'
  2. import triggerEvent from './trigger-event'
  3. import type { DOMWrapper, VueWrapper } from '@vue/test-utils'
  4. const triggerCompositeClick = async <
  5. T extends VueWrapper<any> | DOMWrapper<Element>
  6. >(
  7. wrapper: T
  8. ) => {
  9. await wrapper.trigger('mousedown')
  10. await wrapper.trigger('mouseup')
  11. await wrapper.trigger('click')
  12. }
  13. export default triggerCompositeClick
  14. export const triggerNativeCompositeClick = async (el: Element) => {
  15. triggerEvent(el, 'mousedown')
  16. await nextTick()
  17. triggerEvent(el, 'mouseup')
  18. await nextTick()
  19. triggerEvent(el, 'click')
  20. return nextTick()
  21. }