Skip to content

Commit a63e34d

Browse files
Nick Gravelyneddyerburgh
Nick Gravelyn
authored andcommitted
fix: setProps validates keys against component options (#416)
1 parent 81c40da commit a63e34d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/wrappers/wrapper.js

+6
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,12 @@ export default class Wrapper implements BaseWrapper {
460460
this.vm.$options.propsData = {}
461461
}
462462
Object.keys(data).forEach((key) => {
463+
// Ignore properties that were not specified in the component options
464+
// $FlowIgnore : Problem with possibly null this.vm
465+
if (!this.vm.$options._propKeys.includes(key)) {
466+
return
467+
}
468+
463469
// $FlowIgnore : Problem with possibly null this.vm
464470
if (this.vm._props) {
465471
this.vm._props[key] = data[key]

test/specs/wrapper/setProps.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
3333
expect(wrapper.find('.prop-2').element.textContent).to.equal(prop2)
3434
})
3535

36+
it('does not add properties not defined in component', () => {
37+
const undefinedProp = 'some value'
38+
const wrapper = mountingMethod(ComponentWithProps)
39+
wrapper.setProps({ undefinedProp })
40+
expect(wrapper.props().undefinedProp).to.be.undefined
41+
})
42+
3643
it('runs watch function when prop is updated', () => {
3744
const wrapper = mountingMethod(ComponentWithWatch)
3845
const prop1 = 'testest'

0 commit comments

Comments
 (0)