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

Bug: Optional props are typed as | undefined #2256

Open
DesselBane opened this issue Nov 23, 2023 · 2 comments
Open

Bug: Optional props are typed as | undefined #2256

DesselBane opened this issue Nov 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@DesselBane
Copy link

Describe the bug
When using the .props() method on a VueWrapper for a prop which is not required but has a default value the returned type includes undefined.

To Reproduce
https://github.com/DesselBane/test-utils-reproduction/blob/master/src/components/foo.spec.ts

Expected behavior
I would argue that the type should not include undefined since it has a default value and this default value is returned at runtime.

Related information:
This happened on an update from v2.4.1 to v2.4.2, most likely somewhere in this PR: #2137 (but I'm not sure)

@DesselBane DesselBane added the bug Something isn't working label Nov 23, 2023
@cexbrayat
Copy link
Member

I'm not sure about that.

@pikax What's your take on this?

@pikax
Copy link
Member

pikax commented Nov 23, 2023

I'm actually writing this in the advanced typescript docs here :D

That's caused because the props inferred are the wrong ComponentPublicInstance props, it should be the internal ComponentPublicInstance instead of the rendered props.

Is a bug, at runtime:

    const a = mount(
      defineComponent({
        props: {
          a: {
            type: String,
            default: 'a'
          }
        },
        setup(props) {
          return () => props.a
        }
      })
    )

    expect(a.props('a')).toBe('a')

    a.setProps({ a: undefined })
    expect(a.props('a')).toBe('a')

That's passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants