vue2/test/unit/features/global-api/mixin.spec.js

41 lines
935 B
JavaScript
Raw Normal View History

import Vue from 'vue'
describe('Global API: mixin', () => {
let options
beforeEach(() => { options = Vue.options })
afterEach(() => { Vue.options = options })
it('should work', () => {
const spy = jasmine.createSpy('global mixin')
Vue.mixin({
created () {
spy(this.$options.myOption)
}
})
new Vue({
myOption: 'hello'
})
expect(spy).toHaveBeenCalledWith('hello')
})
it('should work for constructors created before mixin is applied', () => {
const calls = []
const Test = Vue.extend({
2016-06-26 11:18:08 +08:00
name: 'test',
2016-06-28 00:29:59 +08:00
beforeCreate () {
calls.push(this.$options.myOption + ' local')
}
})
Vue.mixin({
2016-06-28 00:29:59 +08:00
beforeCreate () {
calls.push(this.$options.myOption + ' global')
}
})
2016-06-26 11:18:08 +08:00
expect(Test.options.name).toBe('test')
new Test({
myOption: 'hello'
})
expect(calls).toEqual(['hello global', 'hello local'])
})
})