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

_scopeId.spec.ts — vue Source File

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

File typescript 1 imports

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

import Vue from 'vue'

describe('Options _scopeId', () => {
  it('should add scopeId attributes', () => {
    const vm = new Vue({
      _scopeId: 'foo',
      template: '<div><p><span></span></p></div>'
    }).$mount()
    expect(vm.$el.hasAttribute('foo')).toBe(true)
    expect(vm.$el.children[0].hasAttribute('foo')).toBe(true)
    expect(vm.$el.children[0].children[0].hasAttribute('foo')).toBe(true)
  })

  it('should add scopedId attributes from both parent and child on child root', () => {
    const vm = new Vue({
      _scopeId: 'foo',
      template: '<div><child></child></div>',
      components: {
        child: {
          _scopeId: 'bar',
          template: '<div></div>'
        }
      }
    }).$mount()
    expect(vm.$el.children[0].hasAttribute('foo')).toBe(true)
    expect(vm.$el.children[0].hasAttribute('bar')).toBe(true)
  })

  it('should add scopedId attributes from both parent and child on slot contents', () => {
    const vm = new Vue({
      _scopeId: 'foo',
      template: '<div><child><p>hi</p></child></div>',
      components: {
        child: {
          _scopeId: 'bar',
          template: '<div><slot></slot></div>'
        }
      }
    }).$mount()
    expect(vm.$el.children[0].children[0].hasAttribute('foo')).toBe(true)
    expect(vm.$el.children[0].children[0].hasAttribute('bar')).toBe(true)
  })

  // #4774
  it('should not discard parent scopeId when component root element is replaced', done => {
    const vm = new Vue({
      _scopeId: 'data-1',
      template: `<div><child ref="child" /></div>`,
      components: {
        child: {
          _scopeId: 'data-2',
          data: () => ({ show: true }),
          template: '<div v-if="show"></div>'
        }
      }
    }).$mount()

    const child = vm.$refs.child

    expect(child.$el.hasAttribute('data-1')).toBe(true)
    expect(child.$el.hasAttribute('data-2')).toBe(true)

    child.show = false
    waitForUpdate(() => {
      child.show = true
    })
      .then(() => {
        expect(child.$el.hasAttribute('data-1')).toBe(true)
        expect(child.$el.hasAttribute('data-2')).toBe(true)
      })
      .then(done)
  })

  it('should work on functional components', () => {
    const child = {
      functional: true,
      _scopeId: 'child',
      render(h) {
        return h('div', { class: 'child' }, [
          h('span', { class: 'child' }, 'child')
        ])
      }
    }
    const vm = new Vue({
      _scopeId: 'parent',
      components: { child },
      template: '<div><child></child></div>'
    }).$mount()

    expect(vm.$el.hasAttribute('parent')).toBe(true)
    const childEls = vm.$el.querySelectorAll('.child')
    ;[].forEach.call(childEls, el => {
      expect(el.hasAttribute('child')).toBe(true)
      // functional component with scopeId will not inherit parent scopeId
      expect(el.hasAttribute('parent')).toBe(false)
    })
  })
})

Dependencies

  • vue

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free