diff --git a/flow/options.js b/flow/options.js index aec87b967..3e660f554 100644 --- a/flow/options.js +++ b/flow/options.js @@ -3,7 +3,7 @@ declare type Options = { // eslint-disable-line no-undef intercept?: Object, slots?: Object, localVue?: Component, - stub?: Object, + stubs?: Object, context?: Object, clone?: boolean } diff --git a/src/lib/create-instance.js b/src/lib/create-instance.js index 454f498c2..926b2ee1c 100644 --- a/src/lib/create-instance.js +++ b/src/lib/create-instance.js @@ -31,8 +31,8 @@ export default function createConstructor (component: Component, options: Option addProvide(component, options) } - if (options.stub) { - stubComponents(component, options.stub) + if (options.stubs) { + stubComponents(component, options.stubs) } const Constructor = vue.extend(component) diff --git a/test/integration/specs/create-local-vue.js b/test/integration/specs/create-local-vue.js index 072cdd562..9676a592b 100644 --- a/test/integration/specs/create-local-vue.js +++ b/test/integration/specs/create-local-vue.js @@ -13,9 +13,26 @@ describe('createLocalVue', () => { test: 0 }, mutations: { - increment (state) { - state.count++ - } + increment () {} + } + }) + const wrapper = mount(Component, { localVue, store }) + expect(wrapper.vm.$store).to.be.an('object') + const freshWrapper = mount(Component) + expect(typeof freshWrapper.vm.$store).to.equal('undefined') + }) + + it('installs Vuex without polluting global Vue', () => { + const localVue = createLocalVue() + Vuex.installed = false + Vuex.forceInstall = true + localVue.use(Vuex) + const store = new Vuex.Store({ + state: { + test: 0 + }, + mutations: { + increment () {} } }) const wrapper = mount(Component, { localVue, store }) @@ -38,4 +55,13 @@ describe('createLocalVue', () => { const freshWrapper = mount(Component) expect(typeof freshWrapper.vm.$route).to.equal('undefined') }) + + it('sets installed to false inside Vue.use', () => { + const localVue = createLocalVue() + localVue.use(Vuex) + expect(Vuex.installed).to.equal(true) + localVue.use(Vuex) + const freshWrapper = mount(Component) + expect(typeof freshWrapper.vm.$route).to.equal('undefined') + }) }) diff --git a/test/integration/specs/mount/options/clone.spec.js b/test/integration/specs/mount/options/clone.spec.js index d722f713d..c288c69de 100644 --- a/test/integration/specs/mount/options/clone.spec.js +++ b/test/integration/specs/mount/options/clone.spec.js @@ -6,7 +6,7 @@ describe('mount.clone', () => { render: h => h('div') } mount(TestComponent, { - stub: { + stubs: { test: ('
') }, clone: true @@ -19,7 +19,7 @@ describe('mount.clone', () => { render: h => h('div') } mount(TestComponent, { - stub: { + stubs: { test: ('
') } }) @@ -31,7 +31,7 @@ describe('mount.clone', () => { render: h => h('div') } mount(TestComponent, { - stub: { + stubs: { test: ('
') }, clone: false diff --git a/test/integration/specs/mount/options/stub.spec.js b/test/integration/specs/mount/options/stubs.spec.js similarity index 95% rename from test/integration/specs/mount/options/stub.spec.js rename to test/integration/specs/mount/options/stubs.spec.js index 7e8833cf7..61bc60a40 100644 --- a/test/integration/specs/mount/options/stub.spec.js +++ b/test/integration/specs/mount/options/stubs.spec.js @@ -6,7 +6,7 @@ import Component from '~resources/components/component.vue' describe('mount.stub', () => { it('replaces component with template string ', () => { const wrapper = mount(ComponentWithChildComponent, { - stub: { + stubs: { ChildComponent: '
' } }) @@ -17,7 +17,7 @@ describe('mount.stub', () => { it('replaces component with a component', () => { const info = sinon.stub(console, 'info') const wrapper = mount(ComponentWithChildComponent, { - stub: { + stubs: { ChildComponent: { render: h => h('div'), mounted () { @@ -33,7 +33,7 @@ describe('mount.stub', () => { it('does not error if component to stub contains no components', () => { mount(Component, { - stub: { + stubs: { doesNotExist: Component } }) @@ -41,7 +41,7 @@ describe('mount.stub', () => { it('does not modify component directly', () => { const wrapper = mount(ComponentWithNestedChildren, { - stub: { + stubs: { ChildComponent: '
' } }) @@ -55,7 +55,7 @@ describe('mount.stub', () => { render: h => h('registered-component') } const wrapper = mount(ComponentWithGlobalComponent, { - stub: { + stubs: { 'registered-component': Component } }) @@ -68,7 +68,7 @@ describe('mount.stub', () => { render: h => h('registered-component') } mount(ComponentWithGlobalComponent, { - stub: ['registered-component'] + stubs: ['registered-component'] }) expect(warn.called).to.equal(false) @@ -81,7 +81,7 @@ describe('mount.stub', () => { render: h => h('registered-component') } mount(ComponentWithGlobalComponent, { - stub: { + stubs: { 'registered-component': true } }) @@ -97,7 +97,7 @@ describe('mount.stub', () => { const error = '[vue-test-utils]: each item in options.stub must be a string' invalidValues.forEach(invalidValue => { const fn = () => mount(ComponentWithGlobalComponent, { - stub: [invalidValue] + stubs: [invalidValue] }) expect(fn).to.throw().with.property('message', error) }) @@ -108,7 +108,7 @@ describe('mount.stub', () => { const invalidValues = [1, null, [], {}, NaN] invalidValues.forEach(invalidValue => { const fn = () => mount(ComponentWithChildComponent, { - stub: { + stubs: { ChildComponent: invalidValue }}) expect(fn).to.throw().with.property('message', error)