-
Notifications
You must be signed in to change notification settings - Fork 668
fix: Support setProps runs computed and watcher when prop is object (#761) #787
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @flow | ||
|
||
// SetProps on object prop child changes trigger computed or watcher | ||
// https://github.com/vuejs/vue-test-utils/issues/761 | ||
export function createProps (propsData: Object): Object { | ||
return Object.keys(propsData).reduce((props, key) => { | ||
const data = propsData[key] | ||
if ( | ||
typeof data === 'object' && | ||
data !== null && | ||
!Array.isArray(data) | ||
) { | ||
props[key] = Object.assign( | ||
Object.create(Object.getPrototypeOf(data)), | ||
data | ||
) | ||
} else { | ||
props[key] = data | ||
} | ||
return props | ||
}, {}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,9 +52,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { | |
const wrapper = mount(ComponentWithProps, { propsData: { prop1 }}) | ||
expect(wrapper.vm).to.be.an('object') | ||
if (wrapper.vm.$props) { | ||
expect(wrapper.vm.$props.prop1).to.equal(prop1) | ||
expect(wrapper.vm.$props.prop1).to.deep.equal(prop1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking at this fix and I'm not sure we should do it because it changes this behavior. Another solution I could think of was to throw an error and tell the user to call setProps with a new object There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirmed the processing of Vue.js, but it was the same value. So, I thought it would be better not to use
I think that is a good way. But I want to use the same object. |
||
} else { | ||
expect(wrapper.vm.$options.propsData.prop1).to.equal(prop1) | ||
expect(wrapper.vm.$options.propsData.prop1).to.deep.equal(prop1) | ||
} | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just use either the spread opertor (not sure if it will trigger reactivity on nested property objects), or lodash.merge, which we already use in setData.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, use lodash.merge.
(Using spread operators will no longer be instances of classes.)