Skip to content

Commit e671676

Browse files
feedthejimeddyerburgh
authored andcommitted
fix: add support for vue.extended components + add test (#112)
* fix: add support for vue.extended components + add test * Update test
1 parent 5fa01e6 commit e671676

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"sinon": "^2.3.2",
8484
"sinon-chai": "^2.10.0",
8585
"typescript": "^2.4.1",
86-
"vue": "^2.4.4",
86+
"vue": "^2.5.2",
8787
"vue-loader": "^13.0.5",
8888
"vue-router": "^2.7.0",
8989
"vue-template-compiler": "^2.4.4",

src/lib/create-instance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default function createConstructor (component: Component, options: Option
4242
compileTemplate(component)
4343
}
4444

45-
const Constructor = vue.extend(component)
45+
const Constructor = vue.extend(component.extend ? component.options : component)
4646

4747
if (options.mocks) {
4848
addMocks(options.mocks, Constructor)

test/unit/specs/mount.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Vue from 'vue'
12
import { compileToFunctions } from 'vue-template-compiler'
23
import mount from '~src/mount'
34
import ComponentWithProps from '~resources/components/component-with-props.vue'
@@ -41,6 +42,17 @@ describe('mount', () => {
4142
}
4243
})
4344

45+
it('returns new VueWrapper with mounted Vue instance initialized with Vue.extend with props, if passed as propsData', () => {
46+
const prop1 = { test: 'TEST' }
47+
const wrapper = mount(Vue.extend(ComponentWithProps), { propsData: { prop1 }})
48+
expect(wrapper.vm).to.be.an('object')
49+
if (wrapper.vm.$props) {
50+
expect(wrapper.vm.$props.prop1).to.equal(prop1)
51+
} else {
52+
expect(wrapper.vm.$options.propsData.prop1).to.equal(prop1)
53+
}
54+
})
55+
4456
it('does not use cached component', () => {
4557
ComponentWithMixin.methods.someMethod = sinon.stub()
4658
mount(ComponentWithMixin)

0 commit comments

Comments
 (0)