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

watcher.spec.ts — vue Source File

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

File typescript 2 imports

Entity Profile

Dependency Diagram

graph LR
  bf205f9a_b638_599f_1a11_a59ab8307736["watcher.spec.ts"]
  db9e7bef_009d_3918_6e7d_543a36a38d75["vue"]
  bf205f9a_b638_599f_1a11_a59ab8307736 --> db9e7bef_009d_3918_6e7d_543a36a38d75
  b0726a9b_3416_ba5e_8288_ca534387d48d["watcher"]
  bf205f9a_b638_599f_1a11_a59ab8307736 --> b0726a9b_3416_ba5e_8288_ca534387d48d
  style bf205f9a_b638_599f_1a11_a59ab8307736 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import Vue from 'vue'
import Watcher from 'core/observer/watcher'

describe('Watcher', () => {
  let vm, spy
  beforeEach(() => {
    vm = new Vue({
      template: '<div></div>',
      data: {
        a: 1,
        b: {
          c: 2,
          d: 4
        },
        c: 'c',
        msg: 'yo'
      }
    }).$mount()
    spy = vi.fn()
  })

  it('path', done => {
    const watcher = new Watcher(vm, 'b.c', spy)
    expect(watcher.value).toBe(2)
    vm.b.c = 3
    waitForUpdate(() => {
      expect(watcher.value).toBe(3)
      expect(spy).toHaveBeenCalledWith(3, 2)
      vm.b = { c: 4 } // swapping the object
    })
      .then(() => {
        expect(watcher.value).toBe(4)
        expect(spy).toHaveBeenCalledWith(4, 3)
      })
      .then(done)
  })

  it('non-existent path, set later', done => {
    const watcher1 = new Watcher(vm, 'b.e', spy)
    expect(watcher1.value).toBeUndefined()
    // check $add should not affect isolated children
    const child2 = new Vue({ parent: vm })
    const watcher2 = new Watcher(child2, 'b.e', spy)
    expect(watcher2.value).toBeUndefined()
    Vue.set(vm.b, 'e', 123)
    waitForUpdate(() => {
      expect(watcher1.value).toBe(123)
      expect(watcher2.value).toBeUndefined()
      expect(spy.mock.calls.length).toBe(1)
      expect(spy).toHaveBeenCalledWith(123, undefined)
    }).then(done)
  })

  it('delete', done => {
    const watcher = new Watcher(vm, 'b.c', spy)
    expect(watcher.value).toBe(2)
    Vue.delete(vm.b, 'c')
    waitForUpdate(() => {
      expect(watcher.value).toBeUndefined()
      expect(spy).toHaveBeenCalledWith(undefined, 2)
// ... (144 more lines)

Dependencies

  • vue
  • watcher

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free