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: add stub without modifying #1085

Merged
merged 4 commits into from Dec 29, 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
7 changes: 1 addition & 6 deletions packages/create-instance/create-component-stubs.js
Expand Up @@ -167,13 +167,8 @@ export function createStubsFromStubsObject (
if (componentNeedsCompiling(stub)) {
compileTemplate(stub)
}
const name = originalComponents[stubName] &&
originalComponents[stubName].name

acc[stubName] = {
name,
...stub
}
acc[stubName] = stub

return acc
}, {})
Expand Down
40 changes: 32 additions & 8 deletions test/specs/mounting-options/stubs.spec.js
Expand Up @@ -64,18 +64,18 @@ describeWithMountingMethods('options.stub', mountingMethod => {
mountingMethod.name === 'renderToString',
'replaces component with a component',
() => {
const mounted = sinon.stub()
const Stub = {
template: '<div />',
mounted
}
const wrapper = mountingMethod(ComponentWithChild, {
stubs: {
ChildComponent: {
render: h => h('time'),
mounted () {
console.info('stubbed')
}
}
ChildComponent: Stub
}
})
expect(wrapper.findAll(Component).length).to.equal(1)
expect(info.calledWith('stubbed')).to.equal(true)
expect(wrapper.findAll(Stub).length).to.equal(1)
expect(mounted).calledOnce
}
)

Expand Down Expand Up @@ -567,4 +567,28 @@ describeWithMountingMethods('options.stub', mountingMethod => {
)
expect(HTML).to.contain('h1')
})

itDoNotRunIf(
mountingMethod.name === 'renderToString',
'uses original component stub', () => {
const Stub = {
template: '<div />'
}
const ToStub = {
template: '<div />'
}
const TestComponent = {
template: '<div><to-stub /></div>',
components: {
ToStub
}
}
const wrapper = mountingMethod(TestComponent, {
stubs: {
ToStub: Stub
}
})
expect(wrapper.find(ToStub).exists()).to.be.false
expect(wrapper.find(Stub).exists()).to.be.true
})
})