global-assets-api.spec.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Vue from 'vue'
  2. describe('Global Assets API', () => {
  3. const Test = Vue.extend()
  4. it('directive / transition', () => {
  5. const assets = ['directive', 'transition']
  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. it('component', () => {
  16. const def = { a: 1 }
  17. Test.component('test', def)
  18. const component = Test.options.components.test
  19. expect(typeof component).toBe('function')
  20. expect(component.super).toBe(Vue)
  21. expect(component.options.a).toBe(1)
  22. expect(component.options.name).toBe('test')
  23. expect(Test.component('test')).toBe(component)
  24. // already extended
  25. Test.component('test2', component)
  26. expect(Test.component('test2')).toBe(component)
  27. // extended registration should not pollute global
  28. expect(Vue.options.components.test).toBeUndefined()
  29. })
  30. describe('Vue.component works', () => {
  31. it('should register a component', () => {
  32. Vue.component('foo', {
  33. template: '<span>foo</span>'
  34. })
  35. Vue.component('bar', {
  36. template: '<span>bar</span>'
  37. })
  38. const vm = new Vue({
  39. el: document.createElement('div'),
  40. template: '<div><foo></foo><bar></bar></div>'
  41. })
  42. expect(vm.$el.innerHTML).toBe('<span>foo</span><span>bar</span>')
  43. })
  44. })
  45. })