assets.spec.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import Vue from 'vue'
  2. describe('Global API: assets', () => {
  3. const Test = Vue.extend()
  4. it('directive / filters', () => {
  5. const assets = ['directive', 'filter']
  6. assets.forEach(function (type) {
  7. const def = {}
  8. Test[type]('test', def)
  9. expect(Test.options[type + 's'].test).toBe(def)
  10. expect(Test[type]('test')).toBe(def)
  11. // extended registration should not pollute global
  12. expect(Vue.options[type + 's'].test).toBeUndefined()
  13. })
  14. })
  15. describe('Vue.component', () => {
  16. it('should register a component', () => {
  17. Vue.component('foo', {
  18. template: '<span>foo</span>'
  19. })
  20. Vue.component('bar', {
  21. template: '<span>bar</span>'
  22. })
  23. const vm = new Vue({
  24. template: '<div><foo></foo><bar></bar></div>'
  25. }).$mount()
  26. expect(vm.$el.innerHTML).toBe('<span>foo</span><span>bar</span>')
  27. // unregister them
  28. delete Vue.options.components.foo
  29. delete Vue.options.components.bar
  30. })
  31. })
  32. it('component on extended constructor', () => {
  33. const def = { a: 1 }
  34. Test.component('test', def)
  35. const component = Test.options.components.test
  36. expect(typeof component).toBe('function')
  37. expect(component.super).toBe(Vue)
  38. expect(component.options.a).toBe(1)
  39. expect(component.options.name).toBe('test')
  40. expect(Test.component('test')).toBe(component)
  41. // already extended
  42. Test.component('test2', component)
  43. expect(Test.component('test2')).toBe(component)
  44. // extended registration should not pollute global
  45. expect(Vue.options.components.test).toBeUndefined()
  46. })
  47. // #4434
  48. it('local registration should take priority regardless of naming convention', () => {
  49. Vue.component('x-foo', {
  50. template: '<span>global</span>'
  51. })
  52. const vm = new Vue({
  53. components: {
  54. xFoo: {
  55. template: '<span>local</span>'
  56. }
  57. },
  58. template: '<div><x-foo></x-foo></div>'
  59. }).$mount()
  60. expect(vm.$el.textContent).toBe('local')
  61. delete Vue.options.components['x-foo']
  62. })
  63. })