Skip to content

Commit c747cd6

Browse files
authored
fix: add unused propsData as component attributes (#865)
1 parent 4e739bd commit c747cd6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Diff for: packages/create-instance/create-instance.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,13 @@ export default function createInstance (
171171
Constructor,
172172
{
173173
ref: 'vm',
174-
props: options.propsData,
175174
on: options.listeners,
176-
attrs: options.attrs,
175+
attrs: {
176+
...options.attrs,
177+
// pass as attrs so that inheritAttrs works correctly
178+
// propsData should take precedence over attrs
179+
...options.propsData
180+
},
177181
scopedSlots
178182
},
179183
slots

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

+19
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
321321
Vue.config.errorHandler = null
322322
})
323323

324+
it('adds unused propsData as attributes', () => {
325+
const wrapper = mount(
326+
ComponentWithProps, {
327+
attachToDocument: true,
328+
propsData: {
329+
prop1: 'prop1',
330+
extra: 'attr'
331+
},
332+
attrs: {
333+
height: '50px'
334+
}
335+
})
336+
337+
if (vueVersion > 2.3) {
338+
expect(wrapper.vm.$attrs).to.eql({ height: '50px', extra: 'attr' })
339+
}
340+
expect(wrapper.html()).to.equal(`<div height="50px" extra="attr"><p class="prop-1">prop1</p> <p class="prop-2"></p></div>`)
341+
})
342+
324343
it('overwrites the component options with the instance options', () => {
325344
const Component = {
326345
template: '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>',

0 commit comments

Comments
 (0)