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
4 changes: 3 additions & 1 deletion packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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