Skip to content

Commit 1f4876e

Browse files
authored
fix: add stub without modifying (#1085)
1 parent f35cf87 commit 1f4876e

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

Diff for: packages/create-instance/create-component-stubs.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,8 @@ export function createStubsFromStubsObject (
167167
if (componentNeedsCompiling(stub)) {
168168
compileTemplate(stub)
169169
}
170-
const name = originalComponents[stubName] &&
171-
originalComponents[stubName].name
172170

173-
acc[stubName] = {
174-
name,
175-
...stub
176-
}
171+
acc[stubName] = stub
177172

178173
return acc
179174
}, {})

Diff for: test/specs/mounting-options/stubs.spec.js

+32-8
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ describeWithMountingMethods('options.stub', mountingMethod => {
6464
mountingMethod.name === 'renderToString',
6565
'replaces component with a component',
6666
() => {
67+
const mounted = sinon.stub()
68+
const Stub = {
69+
template: '<div />',
70+
mounted
71+
}
6772
const wrapper = mountingMethod(ComponentWithChild, {
6873
stubs: {
69-
ChildComponent: {
70-
render: h => h('time'),
71-
mounted () {
72-
console.info('stubbed')
73-
}
74-
}
74+
ChildComponent: Stub
7575
}
7676
})
77-
expect(wrapper.findAll(Component).length).to.equal(1)
78-
expect(info.calledWith('stubbed')).to.equal(true)
77+
expect(wrapper.findAll(Stub).length).to.equal(1)
78+
expect(mounted).calledOnce
7979
}
8080
)
8181

@@ -567,4 +567,28 @@ describeWithMountingMethods('options.stub', mountingMethod => {
567567
)
568568
expect(HTML).to.contain('h1')
569569
})
570+
571+
itDoNotRunIf(
572+
mountingMethod.name === 'renderToString',
573+
'uses original component stub', () => {
574+
const Stub = {
575+
template: '<div />'
576+
}
577+
const ToStub = {
578+
template: '<div />'
579+
}
580+
const TestComponent = {
581+
template: '<div><to-stub /></div>',
582+
components: {
583+
ToStub
584+
}
585+
}
586+
const wrapper = mountingMethod(TestComponent, {
587+
stubs: {
588+
ToStub: Stub
589+
}
590+
})
591+
expect(wrapper.find(ToStub).exists()).to.be.false
592+
expect(wrapper.find(Stub).exists()).to.be.true
593+
})
570594
})

0 commit comments

Comments
 (0)