Skip to content

Commit

Permalink
fix: keep the overrides prototype information of component (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos authored and eddyerburgh committed Jul 29, 2018
1 parent c747cd6 commit 0371793
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export default function createInstance (
component.options._base = _Vue
}

const Constructor = vueVersion < 2.3 && typeof component === 'function'
// when component constructed by Vue.extend,
// use its own extend method to keep component information
const Constructor = typeof component === 'function'
? component.extend(instanceOptions)
: _Vue.extend(component).extend(instanceOptions)

Expand Down
22 changes: 22 additions & 0 deletions test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
expect(stub).not.called
})

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)
return this
}
Component.prototype.$destroy = function () {
originalDestroy.apply(this)
destroySpy()
}

const wrapper = mount(Component)
expect(mountSpy).called
expect(destroySpy).not.called
wrapper.destroy()
expect(destroySpy).called
})

// Problems accessing options of twice extended components in Vue < 2.3
itDoNotRunIf(vueVersion < 2.3, 'compiles extended components', () => {
const TestComponent = Vue.component('test-component', {
Expand Down

0 comments on commit 0371793

Please sign in to comment.