Skip to content

Commit

Permalink
fix(core): fix merged twice bug when passing extended constructor to …
Browse files Browse the repository at this point in the history
…mixins (vuejs#9199)

fix vuejs#9198
  • Loading branch information
hikerpig authored and hefeng committed Jan 25, 2019
1 parent 7a5cece commit ae6fd71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/core/util/options.js
Expand Up @@ -395,7 +395,7 @@ export function mergeOptions (
}

if (typeof child === 'function') {
child = child.options
child = child.extendOptions
}

normalizeProps(child, vm)
Expand Down
38 changes: 17 additions & 21 deletions test/unit/features/options/mixins.spec.js
Expand Up @@ -110,35 +110,31 @@ describe('Options mixins', () => {
expect(vm.$options.directives.c).toBeDefined()
})

it('should accept further extended constructors as mixins', () => {
const spy1 = jasmine.createSpy('mixinA')
const spy2 = jasmine.createSpy('mixinB')
it('should not mix global mixined lifecycle hook twice', () => {
const spy = jasmine.createSpy('global mixed in lifecycle hook')
Vue.mixin({
created() {
spy()
}
})

const mixinA = Vue.extend({
created: spy1,
directives: {
c: {}
},
const mixin1 = Vue.extend({
methods: {
a: function () {}
a() {}
}
})

const mixinB = mixinA.extend({
created: spy2
const mixin2 = Vue.extend({
mixins: [mixin1],
})

const vm = new Vue({
mixins: [mixinB],
methods: {
b: function () {}
}
const Child = Vue.extend({
mixins: [mixin2],
})

expect(spy1).toHaveBeenCalledTimes(1)
expect(spy2).toHaveBeenCalledTimes(1)
expect(vm.a).toBeDefined()
expect(vm.b).toBeDefined()
expect(vm.$options.directives.c).toBeDefined()
const vm = new Child()

expect(typeof vm.$options.methods.a).toBe('function')
expect(spy.calls.count()).toBe(1)
})
})

0 comments on commit ae6fd71

Please sign in to comment.