Skip to content

Commit d645037

Browse files
committed
fix: delete mounting options before extending component
1 parent a2b1384 commit d645037

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

src/lib/create-instance.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import cloneDeep from 'lodash/cloneDeep'
1111
import { compileTemplate } from './compile-template'
1212
import createLocalVue from '../create-local-vue'
1313
import extractOptions from '../options/extract-options'
14+
import deleteMountingOptions from '../options/delete-mounting-options'
1415

1516
export default function createConstructor (
1617
component: Component,
@@ -57,7 +58,10 @@ export default function createConstructor (
5758

5859
const Constructor = vue.extend(component)
5960

60-
const vm = new Constructor(options)
61+
const instanceOptions = { ...options }
62+
deleteMountingOptions(instanceOptions)
63+
64+
const vm = new Constructor(instanceOptions)
6165

6266
addAttrs(vm, mountingOptions.attrs)
6367
addListeners(vm, mountingOptions.listeners)
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default function deleteMountingOptions (options) {
2+
delete options.custom
3+
delete options.attachToDocument
4+
delete options.mocks
5+
delete options.slots
6+
delete options.localVue
7+
delete options.stubs
8+
delete options.context
9+
delete options.clone
10+
delete options.attrs
11+
delete options.listeners
12+
}

test/unit/specs/mount.spec.js

+43
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { compileToFunctions } from 'vue-template-compiler'
33
import mount from '~src/mount'
44
import ComponentWithProps from '~resources/components/component-with-props.vue'
55
import ComponentWithMixin from '~resources/components/component-with-mixin.vue'
6+
import createLocalVue from '~src/create-local-vue'
67

78
describe('mount', () => {
89
it('returns new VueWrapper with mounted Vue instance if no options are passed', () => {
@@ -86,6 +87,48 @@ describe('mount', () => {
8687
expect(wrapper.html()).to.equal(`<div>foo</div>`)
8788
})
8889

90+
it('deletes mounting options before passing options to component', () => {
91+
const wrapper = mount({
92+
template: `<div>foo</div>`
93+
}, {
94+
provide: {
95+
'prop': 'val'
96+
},
97+
custom: 'custom',
98+
attachToDocument: 'attachToDocument',
99+
mocks: {
100+
'prop': 'val'
101+
},
102+
slots: {
103+
'prop': 'val'
104+
},
105+
localVue: createLocalVue(),
106+
stubs: {
107+
'prop': 'val'
108+
},
109+
clone: 'clone',
110+
attrs: {
111+
'prop': 'val'
112+
},
113+
listeners: {
114+
'prop': 'val'
115+
}
116+
})
117+
debugger
118+
// provide is always a function on an the $options object
119+
expect(typeof wrapper.vm.$options.provide).to.equal('function')
120+
expect(wrapper.vm.$options.custom).to.equal(undefined)
121+
expect(wrapper.vm.$options.attachToDocument).to.equal(undefined)
122+
expect(wrapper.vm.$options.mocks).to.equal(undefined)
123+
expect(wrapper.vm.$options.slots).to.equal(undefined)
124+
expect(wrapper.vm.$options.localVue).to.equal(undefined)
125+
expect(wrapper.vm.$options.stubs).to.equal(undefined)
126+
expect(wrapper.vm.$options.context).to.equal(undefined)
127+
expect(wrapper.vm.$options.clone).to.equal(undefined)
128+
expect(wrapper.vm.$options.attrs).to.equal(undefined)
129+
expect(wrapper.vm.$options.listeners).to.equal(undefined)
130+
})
131+
89132
it.skip('throws an error when the component fails to mount', () => {
90133
const TestComponent = {
91134
template: '<div></div>',

0 commit comments

Comments
 (0)