Skip to content

Commit a5c0e04

Browse files
blake-newmaneddyerburgh
authored andcommitted
fix: Fix clone issue with vue.extend components (#115)
- Moving the previous extend fix logic out to `mount` and `shallow` hooks fixes cloning of component ```js import { mount } from 'vue-test-utils' import ContainerTest from 'container/Test.vue' const options = { mocks: { $route: 'test' } } const wrapper = mount(ContainerTest, options) console.log(wrapper.vm.$route) // test const wrapper2 = mount(ContainerTest) console.log(wrapper2.vm.$route) // test ``` ```js import { mount } from 'vue-test-utils' import ContainerTest from 'container/Test.vue' const options = { mocks: { $route: 'test' } } const wrapper = mount(ContainerTest, options) console.log(wrapper.vm.$route) // test const wrapper2 = mount(ContainerTest) console.log(wrapper2.vm.$route) // undefined ```
1 parent e671676 commit a5c0e04

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

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.extend ? component.options : component)
45+
const Constructor = vue.extend(component)
4646

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

src/mount.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import './lib/matches-polyfill'
1111
Vue.config.productionTip = false
1212

1313
export default function mount (component: Component, options: Options = {}): VueWrapper {
14-
const componentToMount = options.clone === false ? component : cloneDeep(component)
14+
const componentToMount = options.clone === false ? component : cloneDeep(component.extend ? component.options : component)
1515
// Remove cached constructor
1616
delete componentToMount._Ctor
1717

src/shallow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type VueWrapper from './wrappers/vue-wrapper'
1212

1313
export default function shallow (component: Component, options: Options = {}): VueWrapper {
1414
const vue = options.localVue || Vue
15-
const clonedComponent = cloneDeep(component)
15+
const clonedComponent = cloneDeep(component.extend ? component.options : component)
1616

1717
if (clonedComponent.components) {
1818
stubAllComponents(clonedComponent)

0 commit comments

Comments
 (0)