Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,23 @@ export default function createInstance (
component.options._base = _Vue
}

function getExtendedComponent (component, instanceOptions) {
const extendedComponent = component.extend(instanceOptions)
// to keep the possible overridden prototype and _Vue mixins,
// we need change the proto chains manually
// @see https://github.com/vuejs/vue-test-utils/pull/856
// code below equals to
// `extendedComponent.prototype.__proto__.__proto__ = _Vue.prototype`
const extendedComponentProto =
Object.getPrototypeOf(extendedComponent.prototype)
Object.setPrototypeOf(extendedComponentProto, _Vue.prototype)

return extendedComponent
}

// extend component from _Vue to add properties and mixins
const Constructor = typeof component === 'function' && vueVersion < 2.3
? component.extend(instanceOptions)
const Constructor = typeof component === 'function'
? getExtendedComponent(component, instanceOptions)
: _Vue.extend(component).extend(instanceOptions)

Object.keys(instanceOptions.components || {}).forEach(key => {
Expand Down
4 changes: 2 additions & 2 deletions test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
expect(stub).not.called
})

it.skip('overrides component prototype', () => {
it('overrides component prototype', () => {
const mountSpy = sinon.spy()
const destroySpy = sinon.spy()
const Component = Vue.extend({})
const { $mount: originalMount, $destroy: originalDestroy } = Component.prototype
Component.prototype.$mount = function (...args) {
mountSpy()
originalMount.apply(this, args)
mountSpy()
return this
}
Component.prototype.$destroy = function () {
Expand Down