Skip to content
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