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

fix: overwrite object props in the same way as mount #1078

Merged
merged 2 commits into from
Jan 18, 2025

Conversation

wattanx
Copy link
Collaborator

@wattanx wattanx commented Jan 17, 2025 β€’

πŸ”— Linked issue

Fixes: #1072

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

In defu, the first argument takes precedence, so it is not overwritten.
With this fix, props can now be overwritten just like in mount.

Sorry, something went wrong.

@wattanx wattanx marked this pull request as ready for review January 17, 2025 14:40
@wattanx wattanx requested a review from danielroe as a code owner January 17, 2025 14:40
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! ❀️

@danielroe danielroe merged commit 7c76132 into main Jan 18, 2025
4 checks passed
@danielroe danielroe deleted the fix/set-props-behavior branch January 18, 2025 21:11
@github-actions github-actions bot mentioned this pull request Jan 18, 2025
@sebbayer
Copy link

@wattanx thank you very much for the quick fix, but I think that this solution still does not work for wrapper.setProps('propName', null) or setting that prop to undefined because of defu.

I would suggest a simple object merge instead of defu, like this:

return () => h(clonedComponent, { ...props, ...setProps, ...attrs }, slots)

@wattanx
Copy link
Collaborator Author

wattanx commented Jan 21, 2025

Isn't the use of wrapper.setProps('prop', null) not an intended use case in the first place?

image

@sebbayer
Copy link

sebbayer commented Jan 22, 2025 β€’

The only source in the docs I could find was https://vuejs.org/guide/components/props.html#nullable-type

export default {
  props: {
    id: {
      type: [String, null],
      required: true
    }
  }
}

Also on the same page in section "Prop Validation" it says

export default {
  props: {
    // Basic type check
    //  (`null` and `undefined` values will allow any type)
    propA: Number,

And here's a comment by Evan You in the PR where null type was implemented: vuejs/core#3948 (comment)

So in my understanding null can be a possible value, but undefined sets the prop to its default value.

https://vuejs.org/guide/components/props.html#prop-validation

@wattanx
Copy link
Collaborator Author

wattanx commented Jan 22, 2025

@sebbayer

Isn't the use of wrapper.setProps('prop', null) not an intended use case in the first place?

What I mean is that, in @vue/test-utils, the setProps function does not accept a second argument.
https://stackblitz.com/edit/vitest-tests-browser-examples-yoyouz72

https://test-utils.vuejs.org/api/#setProps

setProps(props: Record<string, any>): Promise<void>

@sebbayer
Copy link

Sorry for the confusion, I meant wrapper.setProps({ propName: null }).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrapper.setProps() behaviour for objects is different for mountSuspended vs. mount
3 participants