Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overwrites registered components for stubs #585

Merged
merged 4 commits into from
May 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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