mixin.spec.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import Vue from 'vue'
  2. describe('Global API: mixin', () => {
  3. let options
  4. beforeEach(() => { options = Vue.options })
  5. afterEach(() => { Vue.options = options })
  6. it('should work', () => {
  7. const spy = jasmine.createSpy('global mixin')
  8. Vue.mixin({
  9. created () {
  10. spy(this.$options.myOption)
  11. }
  12. })
  13. new Vue({
  14. myOption: 'hello'
  15. })
  16. expect(spy).toHaveBeenCalledWith('hello')
  17. })
  18. it('should work for constructors created before mixin is applied', () => {
  19. const calls = []
  20. const Test = Vue.extend({
  21. init () {
  22. calls.push(this.$options.myOption + ' local')
  23. }
  24. })
  25. Vue.mixin({
  26. init () {
  27. calls.push(this.$options.myOption + ' global')
  28. }
  29. })
  30. new Test({
  31. myOption: 'hello'
  32. })
  33. expect(calls).toEqual(['hello global', 'hello local'])
  34. })
  35. it('should allow releasing constructors', () => {
  36. const Test = Vue.extend({})
  37. expect(Vue.config._ctors.indexOf(Test) > -1).toBe(true)
  38. Test.release()
  39. expect(Vue.config._ctors.indexOf(Test) > -1).toBe(false)
  40. })
  41. })