global_spec.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. name: 'test',
  13. a: 1,
  14. b: 2
  15. })
  16. expect(Test.options.a).toBe(1)
  17. expect(Test.options.b).toBe(2)
  18. expect(Test.super).toBe(Vue)
  19. // function.name is not available in IE
  20. expect(Test.toString().match(/^function Test\s?\(/)).toBeTruthy()
  21. var t = new Test({
  22. a: 2
  23. })
  24. expect(t.$options.a).toBe(2)
  25. expect(t.$options.b).toBe(2)
  26. // inheritance
  27. var Test2 = Test.extend({
  28. a: 2
  29. })
  30. expect(Test2.options.a).toBe(2)
  31. expect(Test2.options.b).toBe(2)
  32. var t2 = new Test2({
  33. a: 3
  34. })
  35. expect(t2.$options.a).toBe(3)
  36. expect(t2.$options.b).toBe(2)
  37. })
  38. it('use', function () {
  39. var def = {}
  40. var options = {}
  41. var pluginStub = {
  42. install: function (Vue, opts) {
  43. Vue.directive('plugin-test', def)
  44. expect(opts).toBe(options)
  45. }
  46. }
  47. Vue.use(pluginStub, options)
  48. expect(Vue.options.directives['plugin-test']).toBe(def)
  49. delete Vue.options.directives['plugin-test']
  50. // use a function
  51. Vue.use(pluginStub.install, options)
  52. expect(Vue.options.directives['plugin-test']).toBe(def)
  53. delete Vue.options.directives['plugin-test']
  54. })
  55. describe('Asset registration', function () {
  56. var Test = Vue.extend()
  57. it('directive / filter / partial / transition', function () {
  58. [
  59. 'directive',
  60. 'filter',
  61. 'partial',
  62. 'transition'
  63. ].forEach(function (type) {
  64. var def = {}
  65. Test[type]('test', def)
  66. expect(Test.options[type + 's'].test).toBe(def)
  67. expect(Test[type]('test')).toBe(def)
  68. // extended registration should not pollute global
  69. expect(Vue.options[type + 's'].test).toBeUndefined()
  70. })
  71. })
  72. it('component', function () {
  73. var def = { a: 1 }
  74. Test.component('test', def)
  75. var component = Test.options.components.test
  76. expect(typeof component).toBe('function')
  77. expect(component.super).toBe(Vue)
  78. expect(component.options.a).toBe(1)
  79. expect(component.options.name).toBe('test')
  80. expect(Test.component('test')).toBe(component)
  81. // already extended
  82. Test.component('test2', component)
  83. expect(Test.component('test2')).toBe(component)
  84. // extended registration should not pollute global
  85. expect(Vue.options.components.test).toBeUndefined()
  86. })
  87. })
  88. })