_scopeId.spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Vue from 'vue'
  2. describe('Options _scopeId', () => {
  3. it('should add scopeId attributes', () => {
  4. const vm = new Vue({
  5. _scopeId: 'foo',
  6. template: '<div><p><span></span></p></div>'
  7. }).$mount()
  8. expect(vm.$el.hasAttribute('foo')).toBe(true)
  9. expect(vm.$el.children[0].hasAttribute('foo')).toBe(true)
  10. expect(vm.$el.children[0].children[0].hasAttribute('foo')).toBe(true)
  11. })
  12. it('should add scopedId attributes from both parent and child on child root', () => {
  13. const vm = new Vue({
  14. _scopeId: 'foo',
  15. template: '<div><child></child></div>',
  16. components: {
  17. child: {
  18. _scopeId: 'bar',
  19. template: '<div></div>'
  20. }
  21. }
  22. }).$mount()
  23. expect(vm.$el.children[0].hasAttribute('foo')).toBe(true)
  24. expect(vm.$el.children[0].hasAttribute('bar')).toBe(true)
  25. })
  26. it('should add scopedId attributes from both parent and child on slot contents', () => {
  27. const vm = new Vue({
  28. _scopeId: 'foo',
  29. template: '<div><child><p>hi</p></child></div>',
  30. components: {
  31. child: {
  32. _scopeId: 'bar',
  33. template: '<div><slot></slot></div>'
  34. }
  35. }
  36. }).$mount()
  37. expect(vm.$el.children[0].children[0].hasAttribute('foo')).toBe(true)
  38. expect(vm.$el.children[0].children[0].hasAttribute('bar')).toBe(true)
  39. })
  40. })