Skip to content

Commit

Permalink
fix: render children for functional component stubs (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Jul 28, 2018
1 parent 5af3677 commit e2e48dc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
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

0 comments on commit e2e48dc

Please # to comment.