Skip to content

Commit

Permalink
fix: setProps validates keys against component options (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Gravelyn authored and eddyerburgh committed Feb 7, 2018
1 parent 81c40da commit a63e34d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit a63e34d

Please sign in to comment.