Skip to content

Commit 8db502d

Browse files
Akryumeddyerburgh
authored andcommitted
feat: render props on auto stubs (#834)
1 parent ebca3b3 commit 8db502d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ function createBlankStub (
102102
render (h, context) {
103103
return h(
104104
tagName,
105+
{
106+
attrs: componentOptions.functional ? {
107+
...context.props,
108+
...context.data.attrs
109+
} : {
110+
...this.$props
111+
}
112+
},
105113
context ? context.children : this.$slots.default
106114
)
107115
}

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

+35
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,41 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
138138
}
139139
)
140140

141+
itDoNotRunIf(
142+
vueVersion < 2.2, // $props does not exist in Vue < 2.2
143+
'renders stubs props', () => {
144+
const TestComponent = {
145+
template: `<child :prop="propA" attr="hello" />`,
146+
data: () => ({
147+
'propA': 'a'
148+
}),
149+
components: {
150+
child: {
151+
props: ['prop']
152+
}
153+
}
154+
}
155+
const wrapper = shallowMount(TestComponent)
156+
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
157+
})
158+
159+
it('renders stubs props for functional components', () => {
160+
const TestComponent = {
161+
template: `<child :prop="propA" attr="hello" />`,
162+
data: () => ({
163+
'propA': 'a'
164+
}),
165+
components: {
166+
Child: {
167+
props: ['prop'],
168+
functional: true
169+
}
170+
}
171+
}
172+
const wrapper = shallowMount(TestComponent)
173+
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
174+
})
175+
141176
itDoNotRunIf(vueVersion < 2.1, 'handles recursive components', () => {
142177
const TestComponent = {
143178
template: `

0 commit comments

Comments
 (0)