Skip to content

Commit

Permalink
feat: render props on auto stubs (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum authored and eddyerburgh committed Jul 29, 2018
1 parent ebca3b3 commit 8db502d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/shared/stub-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ function createBlankStub (
render (h, context) {
return h(
tagName,
{
attrs: componentOptions.functional ? {
...context.props,
...context.data.attrs
} : {
...this.$props
}
},
context ? context.children : this.$slots.default
)
}
Expand Down
35 changes: 35 additions & 0 deletions test/specs/shallow-mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,41 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
}
)

itDoNotRunIf(
vueVersion < 2.2, // $props does not exist in Vue < 2.2
'renders stubs props', () => {
const TestComponent = {
template: `<child :prop="propA" attr="hello" />`,
data: () => ({
'propA': 'a'
}),
components: {
child: {
props: ['prop']
}
}
}
const wrapper = shallowMount(TestComponent)
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
})

it('renders stubs props for functional components', () => {
const TestComponent = {
template: `<child :prop="propA" attr="hello" />`,
data: () => ({
'propA': 'a'
}),
components: {
Child: {
props: ['prop'],
functional: true
}
}
}
const wrapper = shallowMount(TestComponent)
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
})

itDoNotRunIf(vueVersion < 2.1, 'handles recursive components', () => {
const TestComponent = {
template: `
Expand Down

0 comments on commit 8db502d

Please sign in to comment.