Skip to content

Commit

Permalink
fix: overwrites registered components for stubs (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed May 5, 2018
1 parent db8f393 commit 33a6731
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/create-instance/create-instance.js
Expand Up @@ -59,14 +59,21 @@ export default function createInstance (

const instanceOptions = { ...options }
deleteoptions(instanceOptions)
// $FlowIgnore
const stubComponents = createComponentStubs(component.components, options.stubs)

if (options.stubs) {
instanceOptions.components = {
...instanceOptions.components,
// $FlowIgnore
...createComponentStubs(component.components, options.stubs)
...stubComponents
}
}

Object.keys(stubComponents).forEach(c => {
vue.component(c, stubComponents[c])
})

const vm = new Constructor(instanceOptions)

addAttrs(vm, options.attrs)
Expand Down
20 changes: 20 additions & 0 deletions test/resources/utils.js
Expand Up @@ -80,6 +80,14 @@ export function itSkipIf (predicate, spec, cb) {
}
}

itSkipIf.only = (predicate, spec, cb) => {
if (predicate) {
it.skip(spec, cb)
} else {
it.only(spec, cb)
}
}

export function itDoNotRunIf (predicate, spec, cb) {
if (predicate) {
() => {}
Expand All @@ -88,8 +96,20 @@ export function itDoNotRunIf (predicate, spec, cb) {
}
}

itDoNotRunIf.only = (predicate, spec, cb) => {
if (!predicate) {
it.only(spec, cb)
}
}

export function describeIf (predicate, spec, cb) {
if (predicate) {
describe(spec, cb)
}
}

describeIf.only = (predicate, spec, cb) => {
if (predicate) {
describe(spec, cb)
}
}
17 changes: 17 additions & 0 deletions test/specs/mounting-options/stubs.spec.js
Expand Up @@ -248,6 +248,23 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
expect(HTML).to.contain('<span>')
})

itDoNotRunIf(
mountingMethod.name === 'shallow' ||
mountingMethod.name === 'renderToString',
'stubs on child components', () => {
const TestComponent = {
template: '<transition><span /></transition>'
}

const wrapper = mountingMethod({
components: { 'test-component': TestComponent },
template: '<test-component />'
}, {
stubs: ['transition']
})
expect(wrapper.find('span').exists()).to.equal(false)
})

it('converts config to array if stubs is an array', () => {
const localVue = createLocalVue()
config.stubs['time-component'] = '<p />'
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/setProps.spec.js
Expand Up @@ -105,7 +105,7 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
expect(wrapper.text()).to.equal('There is no message yet')
})

it.only('runs watchers correctly', () => {
it('runs watchers correctly', () => {
const TestComponent = {
template: `<div id="app">
{{ stringified }}
Expand Down

0 comments on commit 33a6731

Please sign in to comment.