Skip to content

Commit fce9da7

Browse files
rssfrncseddyerburgh
authored andcommitted
fix: render children depending on createElement correctly (#198)
1 parent 4753be7 commit fce9da7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/lib/create-instance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function createConstructor (
7474
return h(
7575
clonedComponent,
7676
mountingOptions.context || component.FunctionalRenderContext,
77-
(mountingOptions.context && mountingOptions.context.children) || createFunctionalSlots(mountingOptions.slots, h)
77+
(mountingOptions.context && mountingOptions.context.children && mountingOptions.context.children.map(x => typeof x === 'function' ? x(h) : x)) || createFunctionalSlots(mountingOptions.slots, h)
7878
)
7979
}
8080
}

test/unit/specs/mount/options/context.spec.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('context', () => {
6666
expect(wrapper.element.textContent).to.equal(defaultValue)
6767
})
6868

69-
it('mounts functional component with a defined context.children', () => {
69+
it('mounts functional component with a defined context.children text', () => {
7070
const Component = {
7171
functional: true,
7272
render: (h, { children }) => {
@@ -75,9 +75,24 @@ describe('context', () => {
7575
}
7676
const wrapper = mount(Component, {
7777
context: {
78-
children: ['hello']
78+
children: ['render text']
7979
}
8080
})
81-
expect(wrapper.text()).to.equal('hello')
81+
expect(wrapper.text()).to.equal('render text')
82+
})
83+
84+
it('mounts functional component with a defined context.children element', () => {
85+
const Component = {
86+
functional: true,
87+
render: (h, { children }) => {
88+
return h('div', children)
89+
}
90+
}
91+
const wrapper = mount(Component, {
92+
context: {
93+
children: [h => h('div', 'render component')]
94+
}
95+
})
96+
expect(wrapper.text()).to.equal('render component')
8297
})
8398
})

0 commit comments

Comments
 (0)