You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
9 years ago
|
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({
|
||
|
init () {
|
||
|
calls.push(this.$options.myOption + ' local')
|
||
|
}
|
||
|
})
|
||
|
Vue.mixin({
|
||
|
init () {
|
||
|
calls.push(this.$options.myOption + ' global')
|
||
|
}
|
||
|
})
|
||
|
new Test({
|
||
|
myOption: 'hello'
|
||
|
})
|
||
|
expect(calls).toEqual(['hello global', 'hello local'])
|
||
|
})
|
||
|
|
||
|
it('should allow releasing constructors', () => {
|
||
|
const Test = Vue.extend({})
|
||
|
expect(Vue.config._ctors.indexOf(Test) > -1).toBe(true)
|
||
|
Test.release()
|
||
|
expect(Vue.config._ctors.indexOf(Test) > -1).toBe(false)
|
||
|
})
|
||
|
})
|