Skip to content

Commit

Permalink
refactor: rename options.stub to stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Jul 17, 2017
1 parent 4436f19 commit 0ff0f63
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion flow/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/lib/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 29 additions & 3 deletions test/integration/specs/create-local-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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')
})
})
6 changes: 3 additions & 3 deletions test/integration/specs/mount/options/clone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('mount.clone', () => {
render: h => h('div')
}
mount(TestComponent, {
stub: {
stubs: {
test: ('<div />')
},
clone: true
Expand All @@ -19,7 +19,7 @@ describe('mount.clone', () => {
render: h => h('div')
}
mount(TestComponent, {
stub: {
stubs: {
test: ('<div />')
}
})
Expand All @@ -31,7 +31,7 @@ describe('mount.clone', () => {
render: h => h('div')
}
mount(TestComponent, {
stub: {
stubs: {
test: ('<div />')
},
clone: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div class="stub"></div>'
}
})
Expand All @@ -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 () {
Expand All @@ -33,15 +33,15 @@ describe('mount.stub', () => {

it('does not error if component to stub contains no components', () => {
mount(Component, {
stub: {
stubs: {
doesNotExist: Component
}
})
})

it('does not modify component directly', () => {
const wrapper = mount(ComponentWithNestedChildren, {
stub: {
stubs: {
ChildComponent: '<div />'
}
})
Expand All @@ -55,7 +55,7 @@ describe('mount.stub', () => {
render: h => h('registered-component')
}
const wrapper = mount(ComponentWithGlobalComponent, {
stub: {
stubs: {
'registered-component': Component
}
})
Expand All @@ -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)
Expand All @@ -81,7 +81,7 @@ describe('mount.stub', () => {
render: h => h('registered-component')
}
mount(ComponentWithGlobalComponent, {
stub: {
stubs: {
'registered-component': true
}
})
Expand All @@ -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)
})
Expand All @@ -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)
Expand Down

0 comments on commit 0ff0f63

Please sign in to comment.