Skip to content

Commit 69c7ab2

Browse files
committed
fix: add prototype when createLocalVue is used
1 parent a3dcd27 commit 69c7ab2

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/lib/create-instance.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22

3-
import Vue from 'vue'
43
import addSlots from './add-slots'
54
import addMocks from './add-mocks'
65
import addAttrs from './add-attrs'
@@ -10,12 +9,17 @@ import { stubComponents } from './stub-components'
109
import { throwError } from './util'
1110
import cloneDeep from 'lodash/cloneDeep'
1211
import { compileTemplate } from './compile-template'
12+
import createLocalVue from '../create-local-vue'
1313

1414
export default function createConstructor (
1515
component: Component,
1616
options: Options
1717
): Component {
18-
const vue = options.localVue || Vue
18+
const vue = options.localVue || createLocalVue()
19+
20+
if (options.mocks) {
21+
addMocks(options.mocks, vue)
22+
}
1923

2024
if (component.functional) {
2125
if (options.context && typeof options.context !== 'object') {
@@ -50,10 +54,6 @@ export default function createConstructor (
5054

5155
const Constructor = vue.extend(component)
5256

53-
if (options.mocks) {
54-
addMocks(options.mocks, Constructor)
55-
}
56-
5757
const vm = new Constructor(options)
5858

5959
addAttrs(vm, options.attrs)

test/unit/specs/mount/options/mocks.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import mount from '~src/mount'
2+
import createLocalVue from '~src/create-local-vue'
23
import Component from '~resources/components/component.vue'
4+
import ComponentWithVuex from '~resources/components/component-with-vuex.vue'
35

46
describe('mount.mocks', () => {
57
it('adds variables to vm when passed as mocks object', () => {
@@ -43,6 +45,34 @@ describe('mount.mocks', () => {
4345
expect(wrapper.text()).to.contain('changed value')
4446
})
4547

48+
it('adds variables available to nested vms', () => {
49+
const count = 1
50+
const wrapper = mount({
51+
template: '<div><component-with-vuex /></div>',
52+
components: {
53+
ComponentWithVuex
54+
}
55+
}, {
56+
mocks: { $store: { state: { count, foo: {}}}}
57+
})
58+
expect(wrapper.text()).contains(count)
59+
})
60+
61+
it('adds variables available to nested vms using localVue', () => {
62+
const localVue = createLocalVue()
63+
const count = 1
64+
const wrapper = mount({
65+
template: '<div><component-with-vuex /></div>',
66+
components: {
67+
ComponentWithVuex
68+
}
69+
}, {
70+
mocks: { $store: { state: { count, foo: {}}}},
71+
localVue
72+
})
73+
expect(wrapper.text()).contains(count)
74+
})
75+
4676
it('does not affect global vue class when passed as mocks object', () => {
4777
const $store = { store: true }
4878
const wrapper = mount(Component, {

0 commit comments

Comments
 (0)