Home / File/ events.spec.ts — vue Source File

events.spec.ts — vue Source File

Architecture documentation for events.spec.ts, a typescript file in the vue codebase. 2 imports, 0 dependents.

File typescript 2 imports

Entity Profile

Dependency Diagram

graph LR
  9bb25d5c_8c9b_e55e_8118_36a2f2f68bfe["events.spec.ts"]
  b0751bbf_7c2c_dfea_301f_dc2a72bb6e6c["patch"]
  9bb25d5c_8c9b_e55e_8118_36a2f2f68bfe --> b0751bbf_7c2c_dfea_301f_dc2a72bb6e6c
  f6868225_acf7_afdc_ebd3_15704ddb6566["vnode"]
  9bb25d5c_8c9b_e55e_8118_36a2f2f68bfe --> f6868225_acf7_afdc_ebd3_15704ddb6566
  style 9bb25d5c_8c9b_e55e_8118_36a2f2f68bfe fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { patch } from 'web/runtime/patch'
import VNode from 'core/vdom/vnode'

describe('vdom events module', () => {
  it('should attach event handler to element', () => {
    const click = vi.fn()
    const vnode = new VNode('a', { on: { click } })

    const elm = patch(null, vnode)
    document.body.appendChild(elm)
    global.triggerEvent(elm, 'click')
    expect(click.mock.calls.length).toBe(1)
  })

  it('should not duplicate the same listener', () => {
    const click = vi.fn()
    const vnode1 = new VNode('a', { on: { click } })
    const vnode2 = new VNode('a', { on: { click } })

    const elm = patch(null, vnode1)
    patch(vnode1, vnode2)
    document.body.appendChild(elm)
    global.triggerEvent(elm, 'click')
    expect(click.mock.calls.length).toBe(1)
  })

  it('should update different listener', () => {
    const click = vi.fn()
    const click2 = vi.fn()
    const vnode1 = new VNode('a', { on: { click } })
    const vnode2 = new VNode('a', { on: { click: click2 } })

    const elm = patch(null, vnode1)
    document.body.appendChild(elm)
    global.triggerEvent(elm, 'click')
    expect(click.mock.calls.length).toBe(1)
    expect(click2.mock.calls.length).toBe(0)

    patch(vnode1, vnode2)
    global.triggerEvent(elm, 'click')
    expect(click.mock.calls.length).toBe(1)
    expect(click2.mock.calls.length).toBe(1)
  })

  it('should attach Array of multiple handlers', () => {
    const click = vi.fn()
    const vnode = new VNode('a', { on: { click: [click, click] } })

    const elm = patch(null, vnode)
    document.body.appendChild(elm)
    global.triggerEvent(elm, 'click')
    expect(click.mock.calls.length).toBe(2)
  })

  it('should update Array of multiple handlers', () => {
    const click = vi.fn()
    const click2 = vi.fn()
    const vnode1 = new VNode('a', { on: { click: [click, click2] } })
    const vnode2 = new VNode('a', { on: { click: [click] } })

// ... (76 more lines)

Dependencies

  • patch
  • vnode

Frequently Asked Questions

What does events.spec.ts do?
events.spec.ts is a source file in the vue codebase, written in typescript.
What does events.spec.ts depend on?
events.spec.ts imports 2 module(s): patch, vnode.
Where is events.spec.ts in the architecture?
events.spec.ts is located at test/unit/modules/vdom/modules/events.spec.ts (directory: test/unit/modules/vdom/modules).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free