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
  4169d802_0d6d_14ab_87f3_117e6b48f743["events.spec.ts"]
  22f6e3b3_fd99_35d7_94cf_527e68438cb3["patch"]
  4169d802_0d6d_14ab_87f3_117e6b48f743 --> 22f6e3b3_fd99_35d7_94cf_527e68438cb3
  973389ac_8625_30a3_53ce_b1b48fae58c5["vnode"]
  4169d802_0d6d_14ab_87f3_117e6b48f743 --> 973389ac_8625_30a3_53ce_b1b48fae58c5
  style 4169d802_0d6d_14ab_87f3_117e6b48f743 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