Skip to content

fix(core): setProps validates keys against component options #416

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

Merged
merged 1 commit into from Feb 7, 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
6 changes: 6 additions & 0 deletions src/wrappers/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ export default class Wrapper implements BaseWrapper {
this.vm.$options.propsData = {}
}
Object.keys(data).forEach((key) => {
// Ignore properties that were not specified in the component options
// $FlowIgnore : Problem with possibly null this.vm
if (!this.vm.$options._propKeys.includes(key)) {
return
}

// $FlowIgnore : Problem with possibly null this.vm
if (this.vm._props) {
this.vm._props[key] = data[key]
Expand Down
7 changes: 7 additions & 0 deletions test/specs/wrapper/setProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
expect(wrapper.find('.prop-2').element.textContent).to.equal(prop2)
})

it('does not add properties not defined in component', () => {
const undefinedProp = 'some value'
const wrapper = mountingMethod(ComponentWithProps)
wrapper.setProps({ undefinedProp })
expect(wrapper.props().undefinedProp).to.be.undefined
})

it('runs watch function when prop is updated', () => {
const wrapper = mountingMethod(ComponentWithWatch)
const prop1 = 'testest'
Expand Down