import { patchEvent } from '../../src/modules/events'
-import { nextTick } from '@vue/runtime-dom'
+
+const timeout = () => new Promise(r => setTimeout(r))
describe(`events`, () => {
it('should assign event handler', async () => {
const fn = jest.fn()
patchEvent(el, 'click', null, fn, null)
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
expect(fn).toHaveBeenCalledTimes(3)
})
patchEvent(el, 'click', null, prevFn, null)
el.dispatchEvent(event)
patchEvent(el, 'click', prevFn, nextFn, null)
- await nextTick()
+ await timeout()
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
expect(prevFn).toHaveBeenCalledTimes(1)
expect(nextFn).toHaveBeenCalledTimes(2)
})
const fn2 = jest.fn()
patchEvent(el, 'click', null, [fn1, fn2], null)
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
expect(fn1).toHaveBeenCalledTimes(1)
expect(fn2).toHaveBeenCalledTimes(1)
})
patchEvent(el, 'click', null, fn, null)
patchEvent(el, 'click', fn, null, null)
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
expect(fn).not.toHaveBeenCalled()
})
}
patchEvent(el, 'click', null, nextValue, null)
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
expect(fn).toHaveBeenCalledTimes(1)
})
patchEvent(el, 'click', null, prevFn, null)
patchEvent(el, 'click', prevFn, nextValue, null)
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
expect(prevFn).not.toHaveBeenCalled()
expect(nextFn).toHaveBeenCalledTimes(1)
})
patchEvent(el, 'click', null, nextValue, null)
patchEvent(el, 'click', nextValue, null, null)
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
el.dispatchEvent(event)
- await nextTick()
+ await timeout()
expect(fn).not.toHaveBeenCalled()
})
})