How to use the @vue/runtime-dom.withKeys function in @vue/runtime-dom

To help you get started, we’ve selected a few @vue/runtime-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-next / packages / runtime-dom / __tests__ / directives / vOn.spec.ts View on Github external
test('it should support key modifiers and system modifiers', () => {
    const el = document.createElement('div')
    const fn = jest.fn()
    // <div>
    const nextValue = withKeys(withModifiers(fn, ['ctrl']), [
      'esc',
      'arrow-left'
    ])
    patchEvent(el, 'keyup', null, nextValue, null)

    triggerEvent(el, 'keyup', e =&gt; (e.key = 'a'))
    expect(fn).not.toBeCalled()

    triggerEvent(el, 'keyup', e =&gt; {
      e.ctrlKey = false
      e.key = 'esc'
    })
    expect(fn).not.toBeCalled()

    triggerEvent(el, 'keyup', e =&gt; {
      e.ctrlKey = true</div>
github vuejs / vue-next / packages / runtime-dom / __tests__ / directives / vOn.spec.ts View on Github external
test('it should support "exact" modifier', () =&gt; {
    const el = document.createElement('div')
    // Case 1: <div>
    const fn1 = jest.fn()
    const next1 = withModifiers(fn1, ['exact'])
    patchEvent(el, 'keyup', null, next1, null)
    triggerEvent(el, 'keyup')
    expect(fn1.mock.calls.length).toBe(1)
    triggerEvent(el, 'keyup', e =&gt; (e.ctrlKey = true))
    expect(fn1.mock.calls.length).toBe(1)
    // Case 2: <div>
    const fn2 = jest.fn()
    const next2 = withKeys(withModifiers(fn2, ['ctrl', 'exact']), ['a'])
    patchEvent(el, 'keyup', null, next2, null)
    triggerEvent(el, 'keyup', e =&gt; (e.key = 'a'))
    expect(fn2).not.toBeCalled()
    triggerEvent(el, 'keyup', e =&gt; {
      e.key = 'a'
      e.ctrlKey = true
    })
    expect(fn2.mock.calls.length).toBe(1)
    triggerEvent(el, 'keyup', e =&gt; {
      // should not trigger if has other system modifiers
      e.key = 'a'
      e.ctrlKey = true
      e.altKey = true
    })
    expect(fn2.mock.calls.length).toBe(1)
  })</div></div>