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

dep.spec.ts — vue Source File

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

File typescript 1 imports

Entity Profile

Dependency Diagram

graph LR
  09ec4e4f_c084_370a_77ad_504033d17587["dep.spec.ts"]
  249e9921_5d55_45a6_e589_ee123f22bc67["dep"]
  09ec4e4f_c084_370a_77ad_504033d17587 --> 249e9921_5d55_45a6_e589_ee123f22bc67
  style 09ec4e4f_c084_370a_77ad_504033d17587 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import Dep, { cleanupDeps } from 'core/observer/dep'

describe('Dep', () => {
  let dep

  beforeEach(() => {
    dep = new Dep()
  })

  describe('instance', () => {
    it('should be created with correct properties', () => {
      expect(dep.subs.length).toBe(0)
      expect(new Dep().id).toBe(dep.id + 1)
    })
  })

  describe('addSub()', () => {
    it('should add sub', () => {
      dep.addSub(null)
      expect(dep.subs.length).toBe(1)
      expect(dep.subs[0]).toBe(null)
    })
  })

  describe('removeSub()', () => {
    it('should remove sub', () => {
      const sub = {}
      dep.subs.push(sub)
      dep.removeSub(sub)
      expect(dep.subs.includes(sub)).toBe(false)

      // nulled subs are cleared on next flush
      cleanupDeps()
      expect(dep.subs.length).toBe(0)
    })
  })

  describe('depend()', () => {
    let _target

    beforeAll(() => {
      _target = Dep.target
    })

    afterAll(() => {
      Dep.target = _target
    })

    it('should do nothing if no target', () => {
      Dep.target = null
      dep.depend()
    })

    it('should add itself to target', () => {
      Dep.target = { addDep: vi.fn() } as any
      dep.depend()
      expect(Dep.target!.addDep).toHaveBeenCalledWith(dep)
    })
  })

  describe('notify()', () => {
    it('should notify subs', () => {
      dep.subs.push({ update: vi.fn() })
      dep.notify()
      expect(dep.subs[0].update).toHaveBeenCalled()
    })
  })
})

Dependencies

  • dep

Frequently Asked Questions

What does dep.spec.ts do?
dep.spec.ts is a source file in the vue codebase, written in typescript.
What does dep.spec.ts depend on?
dep.spec.ts imports 1 module(s): dep.
Where is dep.spec.ts in the architecture?
dep.spec.ts is located at test/unit/modules/observer/dep.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