mixin.spec.js 935 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. name: 'test',
  22. beforeCreate () {
  23. calls.push(this.$options.myOption + ' local')
  24. }
  25. })
  26. Vue.mixin({
  27. beforeCreate () {
  28. calls.push(this.$options.myOption + ' global')
  29. }
  30. })
  31. expect(Test.options.name).toBe('test')
  32. new Test({
  33. myOption: 'hello'
  34. })
  35. expect(calls).toEqual(['hello global', 'hello local'])
  36. })
  37. })