Skip to content

Commit e2e48dc

Browse files
authored
fix: render children for functional component stubs (#860)
1 parent 5af3677 commit e2e48dc

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

Diff for: packages/shared/stub-components.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ function createBlankStub (
9999

100100
return {
101101
...getCoreProperties(componentOptions),
102-
render (h) {
102+
render (h, context) {
103103
return h(
104104
tagName,
105-
!componentOptions.functional && this.$slots.default
105+
context ? context.children : this.$slots.default
106106
)
107107
}
108108
}

Diff for: test/specs/shallow-mount.spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,44 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
6363
expect(console.info.callCount).to.equal(4)
6464
})
6565

66+
it('renders children', () => {
67+
const localVue = createLocalVue()
68+
localVue.component('child', {
69+
template: '<div />'
70+
})
71+
const TestComponent = {
72+
template: `<child>{{'Hello'}}</child>`
73+
}
74+
const wrapper = shallowMount(TestComponent, {
75+
localVue
76+
})
77+
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
78+
})
79+
80+
it('renders no children if none supplied', () => {
81+
const TestComponent = {
82+
template: '<child />',
83+
components: { Child: { }}
84+
}
85+
const wrapper = shallowMount(TestComponent)
86+
expect(wrapper.html()).to.equal('<child-stub></child-stub>')
87+
})
88+
89+
it('renders children for functional components', () => {
90+
const localVue = createLocalVue()
91+
localVue.component('child', {
92+
template: '<div />',
93+
functional: true
94+
})
95+
const TestComponent = {
96+
template: `<child>{{'Hello'}}</child>`
97+
}
98+
const wrapper = shallowMount(TestComponent, {
99+
localVue
100+
})
101+
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
102+
})
103+
66104
it('stubs globally registered components', () => {
67105
Vue.component('registered-component', ComponentWithLifecycleHooks)
68106
const Component = {

0 commit comments

Comments
 (0)