Skip to content

Commit 0ff0f63

Browse files
committed
refactor: rename options.stub to stubs
1 parent 4436f19 commit 0ff0f63

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

flow/options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare type Options = { // eslint-disable-line no-undef
33
intercept?: Object,
44
slots?: Object,
55
localVue?: Component,
6-
stub?: Object,
6+
stubs?: Object,
77
context?: Object,
88
clone?: boolean
99
}

src/lib/create-instance.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default function createConstructor (component: Component, options: Option
3131
addProvide(component, options)
3232
}
3333

34-
if (options.stub) {
35-
stubComponents(component, options.stub)
34+
if (options.stubs) {
35+
stubComponents(component, options.stubs)
3636
}
3737

3838
const Constructor = vue.extend(component)

test/integration/specs/create-local-vue.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,26 @@ describe('createLocalVue', () => {
1313
test: 0
1414
},
1515
mutations: {
16-
increment (state) {
17-
state.count++
18-
}
16+
increment () {}
17+
}
18+
})
19+
const wrapper = mount(Component, { localVue, store })
20+
expect(wrapper.vm.$store).to.be.an('object')
21+
const freshWrapper = mount(Component)
22+
expect(typeof freshWrapper.vm.$store).to.equal('undefined')
23+
})
24+
25+
it('installs Vuex without polluting global Vue', () => {
26+
const localVue = createLocalVue()
27+
Vuex.installed = false
28+
Vuex.forceInstall = true
29+
localVue.use(Vuex)
30+
const store = new Vuex.Store({
31+
state: {
32+
test: 0
33+
},
34+
mutations: {
35+
increment () {}
1936
}
2037
})
2138
const wrapper = mount(Component, { localVue, store })
@@ -38,4 +55,13 @@ describe('createLocalVue', () => {
3855
const freshWrapper = mount(Component)
3956
expect(typeof freshWrapper.vm.$route).to.equal('undefined')
4057
})
58+
59+
it('sets installed to false inside Vue.use', () => {
60+
const localVue = createLocalVue()
61+
localVue.use(Vuex)
62+
expect(Vuex.installed).to.equal(true)
63+
localVue.use(Vuex)
64+
const freshWrapper = mount(Component)
65+
expect(typeof freshWrapper.vm.$route).to.equal('undefined')
66+
})
4167
})

test/integration/specs/mount/options/clone.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('mount.clone', () => {
66
render: h => h('div')
77
}
88
mount(TestComponent, {
9-
stub: {
9+
stubs: {
1010
test: ('<div />')
1111
},
1212
clone: true
@@ -19,7 +19,7 @@ describe('mount.clone', () => {
1919
render: h => h('div')
2020
}
2121
mount(TestComponent, {
22-
stub: {
22+
stubs: {
2323
test: ('<div />')
2424
}
2525
})
@@ -31,7 +31,7 @@ describe('mount.clone', () => {
3131
render: h => h('div')
3232
}
3333
mount(TestComponent, {
34-
stub: {
34+
stubs: {
3535
test: ('<div />')
3636
},
3737
clone: false

test/integration/specs/mount/options/stub.spec.js renamed to test/integration/specs/mount/options/stubs.spec.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Component from '~resources/components/component.vue'
66
describe('mount.stub', () => {
77
it('replaces component with template string ', () => {
88
const wrapper = mount(ComponentWithChildComponent, {
9-
stub: {
9+
stubs: {
1010
ChildComponent: '<div class="stub"></div>'
1111
}
1212
})
@@ -17,7 +17,7 @@ describe('mount.stub', () => {
1717
it('replaces component with a component', () => {
1818
const info = sinon.stub(console, 'info')
1919
const wrapper = mount(ComponentWithChildComponent, {
20-
stub: {
20+
stubs: {
2121
ChildComponent: {
2222
render: h => h('div'),
2323
mounted () {
@@ -33,15 +33,15 @@ describe('mount.stub', () => {
3333

3434
it('does not error if component to stub contains no components', () => {
3535
mount(Component, {
36-
stub: {
36+
stubs: {
3737
doesNotExist: Component
3838
}
3939
})
4040
})
4141

4242
it('does not modify component directly', () => {
4343
const wrapper = mount(ComponentWithNestedChildren, {
44-
stub: {
44+
stubs: {
4545
ChildComponent: '<div />'
4646
}
4747
})
@@ -55,7 +55,7 @@ describe('mount.stub', () => {
5555
render: h => h('registered-component')
5656
}
5757
const wrapper = mount(ComponentWithGlobalComponent, {
58-
stub: {
58+
stubs: {
5959
'registered-component': Component
6060
}
6161
})
@@ -68,7 +68,7 @@ describe('mount.stub', () => {
6868
render: h => h('registered-component')
6969
}
7070
mount(ComponentWithGlobalComponent, {
71-
stub: ['registered-component']
71+
stubs: ['registered-component']
7272
})
7373

7474
expect(warn.called).to.equal(false)
@@ -81,7 +81,7 @@ describe('mount.stub', () => {
8181
render: h => h('registered-component')
8282
}
8383
mount(ComponentWithGlobalComponent, {
84-
stub: {
84+
stubs: {
8585
'registered-component': true
8686
}
8787
})
@@ -97,7 +97,7 @@ describe('mount.stub', () => {
9797
const error = '[vue-test-utils]: each item in options.stub must be a string'
9898
invalidValues.forEach(invalidValue => {
9999
const fn = () => mount(ComponentWithGlobalComponent, {
100-
stub: [invalidValue]
100+
stubs: [invalidValue]
101101
})
102102
expect(fn).to.throw().with.property('message', error)
103103
})
@@ -108,7 +108,7 @@ describe('mount.stub', () => {
108108
const invalidValues = [1, null, [], {}, NaN]
109109
invalidValues.forEach(invalidValue => {
110110
const fn = () => mount(ComponentWithChildComponent, {
111-
stub: {
111+
stubs: {
112112
ChildComponent: invalidValue
113113
}})
114114
expect(fn).to.throw().with.property('message', error)

0 commit comments

Comments
 (0)