-
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
Conversation
// 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) => { |
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.)
test/specs/mount.spec.js
Outdated
@@ -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 comment
The 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 comment
The 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 deep
.
Another solution I could think of was to throw an error and tell the user to call setProps with a new object.
I think that is a good way. But I want to use the same object.
I'll look into a way to fix again.
Changes
|
This is a good solution, but it still suffers from this problem:
I think a better solution would be to throw an error if the object in setProps has the same reference, and make the user create a new object. That way we situations that might be confusing, like the above. |
Hmmm, I can't think of a way to pass the test. |
Related: #761
Changes
mount.spec.js
has been updated