Skip to content

Commit

Permalink
fix: add stub without modifying (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Dec 29, 2018
1 parent f35cf87 commit 1f4876e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
7 changes: 1 addition & 6 deletions packages/create-instance/create-component-stubs.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
})
})

0 comments on commit 1f4876e

Please sign in to comment.