2
0

use.spec.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Vue from 'vue'
  2. describe('Global API: use', () => {
  3. const def = {}
  4. const options = {}
  5. const pluginStub = {
  6. install: (Vue, opts) => {
  7. Vue.directive('plugin-test', def)
  8. expect(opts).toBe(options)
  9. }
  10. }
  11. it('should apply Object plugin', () => {
  12. Vue.use(pluginStub, options)
  13. expect(Vue.options.directives['plugin-test']).toBe(def)
  14. delete Vue.options.directives['plugin-test']
  15. expect(Vue.options.directives['plugin-test']).toBeUndefined()
  16. // should not double apply
  17. Vue.use(pluginStub, options)
  18. expect(Vue.options.directives['plugin-test']).toBeUndefined()
  19. })
  20. it('should apply Function plugin', () => {
  21. Vue.use(pluginStub.install, options)
  22. expect(Vue.options.directives['plugin-test']).toBe(def)
  23. delete Vue.options.directives['plugin-test']
  24. })
  25. it('should work on extended constructors without polluting the base', () => {
  26. const Ctor = Vue.extend({})
  27. Ctor.use(pluginStub, options)
  28. expect(Vue.options.directives['plugin-test']).toBeUndefined()
  29. expect(Ctor.options.directives['plugin-test']).toBe(def)
  30. })
  31. // GitHub issue #5970
  32. it('should work on multi version', () => {
  33. const Ctor1 = Vue.extend({})
  34. const Ctor2 = Vue.extend({})
  35. Ctor1.use(pluginStub, options)
  36. expect(Vue.options.directives['plugin-test']).toBeUndefined()
  37. expect(Ctor1.options.directives['plugin-test']).toBe(def)
  38. // multi version Vue Ctor with the same cid
  39. Ctor2.cid = Ctor1.cid
  40. Ctor2.use(pluginStub, options)
  41. expect(Vue.options.directives['plugin-test']).toBeUndefined()
  42. expect(Ctor2.options.directives['plugin-test']).toBe(def)
  43. })
  44. // #8595
  45. it('chain call', () => {
  46. expect(Vue.use(() => {})).toBe(Vue)
  47. })
  48. })