Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add unused propsData as component attributes #865

Merged
merged 1 commit into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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