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
13 changes: 13 additions & 0 deletions packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,19 @@ export default class Wrapper implements BaseWrapper {
`is not defined on the component`
)
}
if (
typeof data[key] === 'object' &&
data[key] !== null &&
// $FlowIgnore : Problem with possibly null this.vm
data[key] === this.vm[key]
) {
throwError(
`wrapper.setProps() called with the same object ` +
`of the existing ${key} property. ` +
`You must call wrapper.setProps() with a new object ` +
`to trigger reactivity`
)
}

if (this.vm && this.vm._props) {
this.vm._props[key] = data[key]
Expand Down
30 changes: 30 additions & 0 deletions test/specs/wrapper/setProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ describeWithShallowAndMount('setProps', mountingMethod => {
expect(wrapper.vm.data).to.equal('1,2,3,4,5')
})

it('should same reference when called with same object', () => {
const TestComponent = {
template: `<div></div>`,
props: ['obj']
}
const wrapper = mountingMethod(TestComponent)
const obj = {}
wrapper.setProps({ obj })
expect(wrapper.props().obj).to.equal(obj)
})

it('throws an error if property is same reference', () => {
const TestComponent = {
template: `<div></div>`,
props: ['obj']
}
const obj = {}
const wrapper = mountingMethod(TestComponent, {
propsData: {
obj
}
})

const message = '[vue-test-utils]: wrapper.setProps() called with the same object of the existing obj property. You must call wrapper.setProps() with a new object to trigger reactivity'
const fn = () => wrapper.setProps({ obj })
expect(fn)
.to.throw()
.with.property('message', message)
})

it('throws an error if node is not a Vue instance', () => {
const message = 'wrapper.setProps() can only be called on a Vue instance'
const compiled = compileToFunctions('<div><p></p></div>')
Expand Down