Skip to content

Commit

Permalink
fix: add unused propsData as component attributes (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Jul 29, 2018
1 parent 4e739bd commit c747cd6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ export default function createInstance (
Constructor,
{
ref: 'vm',
props: options.propsData,
on: options.listeners,
attrs: options.attrs,
attrs: {
...options.attrs,
// pass as attrs so that inheritAttrs works correctly
// propsData should take precedence over attrs
...options.propsData
},
scopedSlots
},
slots
Expand Down
19 changes: 19 additions & 0 deletions test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,25 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
Vue.config.errorHandler = null
})

it('adds unused propsData as attributes', () => {
const wrapper = mount(
ComponentWithProps, {
attachToDocument: true,
propsData: {
prop1: 'prop1',
extra: 'attr'
},
attrs: {
height: '50px'
}
})

if (vueVersion > 2.3) {
expect(wrapper.vm.$attrs).to.eql({ height: '50px', extra: 'attr' })
}
expect(wrapper.html()).to.equal(`<div height="50px" extra="attr"><p class="prop-1">prop1</p> <p class="prop-2"></p></div>`)
})

it('overwrites the component options with the instance options', () => {
const Component = {
template: '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>',
Expand Down

0 comments on commit c747cd6

Please sign in to comment.