Skip to content

fix: render children for functional components #860

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

Merged
merged 1 commit into from
Jul 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/shared/stub-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ function createBlankStub (

return {
...getCoreProperties(componentOptions),
render (h) {
render (h, context) {
return h(
tagName,
!componentOptions.functional && this.$slots.default
context ? context.children : this.$slots.default
)
}
}
Expand Down
38 changes: 38 additions & 0 deletions test/specs/shallow-mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,44 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
expect(console.info.callCount).to.equal(4)
})

it('renders children', () => {
const localVue = createLocalVue()
localVue.component('child', {
template: '<div />'
})
const TestComponent = {
template: `<child>{{'Hello'}}</child>`
}
const wrapper = shallowMount(TestComponent, {
localVue
})
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
})

it('renders no children if none supplied', () => {
const TestComponent = {
template: '<child />',
components: { Child: { }}
}
const wrapper = shallowMount(TestComponent)
expect(wrapper.html()).to.equal('<child-stub></child-stub>')
})

it('renders children for functional components', () => {
const localVue = createLocalVue()
localVue.component('child', {
template: '<div />',
functional: true
})
const TestComponent = {
template: `<child>{{'Hello'}}</child>`
}
const wrapper = shallowMount(TestComponent, {
localVue
})
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
})

it('stubs globally registered components', () => {
Vue.component('registered-component', ComponentWithLifecycleHooks)
const Component = {
Expand Down