use.spec.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. })