global_spec.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. var Vue = require('../../../../src/vue')
  2. var _ = require('../../../../src/util')
  3. var config = require('../../../../src/config')
  4. describe('Global API', function () {
  5. it('exposed utilities', function () {
  6. expect(Vue.util).toBe(_)
  7. expect(Vue.nextTick).toBe(_.nextTick)
  8. expect(Vue.config).toBe(config)
  9. })
  10. it('extend', function () {
  11. var Test = Vue.extend({
  12. a: 1,
  13. b: 2
  14. })
  15. expect(Test.options.a).toBe(1)
  16. expect(Test.options.b).toBe(2)
  17. expect(Test.super).toBe(Vue)
  18. var t = new Test({
  19. a: 2
  20. })
  21. expect(t.$options.a).toBe(2)
  22. expect(t.$options.b).toBe(2)
  23. // inheritance
  24. var Test2 = Test.extend({
  25. a: 2
  26. })
  27. expect(Test2.options.a).toBe(2)
  28. expect(Test2.options.b).toBe(2)
  29. var t2 = new Test2({
  30. a: 3
  31. })
  32. expect(t2.$options.a).toBe(3)
  33. expect(t2.$options.b).toBe(2)
  34. })
  35. it('use', function () {
  36. var def = {}
  37. var options = {}
  38. var pluginStub = {
  39. install: function (Vue, opts) {
  40. Vue.directive('plugin-test', def)
  41. expect(opts).toBe(options)
  42. }
  43. }
  44. Vue.use(pluginStub, options)
  45. expect(Vue.options.directives['plugin-test']).toBe(def)
  46. delete Vue.options.directives['plugin-test']
  47. // use a function
  48. Vue.use(pluginStub.install, options)
  49. expect(Vue.options.directives['plugin-test']).toBe(def)
  50. delete Vue.options.directives['plugin-test']
  51. })
  52. describe('Asset registration', function () {
  53. var Test = Vue.extend()
  54. it('directive / filter / partial / transition', function () {
  55. [
  56. 'directive',
  57. 'filter',
  58. 'partial',
  59. 'transition'
  60. ].forEach(function (type) {
  61. var def = {}
  62. Test[type]('test', def)
  63. expect(Test.options[type + 's'].test).toBe(def)
  64. expect(Test[type]('test')).toBe(def)
  65. // extended registration should not pollute global
  66. expect(Vue.options[type + 's'].test).toBeUndefined()
  67. })
  68. })
  69. it('component', function () {
  70. var def = { a: 1 }
  71. Test.component('test', def)
  72. var component = Test.options.components.test
  73. expect(typeof component).toBe('function')
  74. expect(component.super).toBe(Vue)
  75. expect(component.options.a).toBe(1)
  76. expect(Test.component('test')).toBe(component)
  77. // already extended
  78. Test.component('test2', component)
  79. expect(Test.component('test2')).toBe(component)
  80. // extended registration should not pollute global
  81. expect(Vue.options.components.test).toBeUndefined()
  82. })
  83. })
  84. })