Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#9198): fix merged twice bug when passing extended constructor to mixins #9199

Merged
merged 1 commit into from Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/util/options.js
Expand Up @@ -376,13 +376,13 @@ export function mergeOptions (
}

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

normalizeProps(child, vm)
normalizeInject(child, vm)
normalizeDirectives(child)

// Apply extends and mixins on the child options,
// but only if it is a raw options object that isn't
// the result of another mergeOptions call.
Expand Down
28 changes: 28 additions & 0 deletions test/unit/features/options/mixins.spec.js
Expand Up @@ -109,4 +109,32 @@ describe('Options mixins', () => {
expect(vm.b).toBeDefined()
expect(vm.$options.directives.c).toBeDefined()
})

it('should not mix global mixined lifecycle hook twice', () => {
const spy = jasmine.createSpy('global mixed in lifecycle hook')
Vue.mixin({
created() {
spy()
}
})

const mixin1 = Vue.extend({
methods: {
a() {}
}
})

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

const Child = Vue.extend({
mixins: [mixin2],
})

const vm = new Child()

expect(typeof vm.$options.methods.a).toBe('function')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this test for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is to make sure the fix does not break normal inheritance from grandparent, in this test, mixin1 and Child

expect(spy.calls.count()).toBe(1)
})
})