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: Props detection broken with jest since 2.4.2 (works in 2.4.1) #561

Open
sawmurai opened this issue Mar 19, 2024 · 7 comments
Open

Bug: Props detection broken with jest since 2.4.2 (works in 2.4.1) #561

sawmurai opened this issue Mar 19, 2024 · 7 comments
Labels

Comments

@sawmurai
Copy link

sawmurai commented Mar 19, 2024

Describe the bug
Since upgrading from 2.4.1 props are no longer properly detected if the component is imported from a SFC. Please see the reproducer linked below.

The following error is shown if I run the tests:

❯ jest
 FAIL  src/components/HelloWorld.spec.ts
  ● Test suite failed to run

    src/components/HelloWorld.spec.ts:13:26 - error TS2339: Property 'msg' does not exist on type '{ key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | VNodeMountHook[] | undefined; ... 6 more ...; style?: unknown; } & Partial<...> & Omit<...>'.

    13   expect(wrapper.props().msg).toBe('Hello world');
                                ~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.625 s
Ran all test suites.

To Reproduce

https://stackblitz.com/edit/vitejs-vite-wdomed?file=src%2Fcomponents%2FHelloWorld.spec.ts

Expected behavior
Prop is still detected, or at least "ignored".

Related information:

System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
npmPackages:
@vue/test-utils: ^2.4.5 => 2.4.5
jest: ^29.7.0 => 29.7.0
vue: ^3.4.21 => 3.4.21

Additional context

@sawmurai sawmurai added the bug label Mar 19, 2024
@cexbrayat
Copy link
Member

Hi @sawmurai

Thanks for the repro.
I think the regression occurred between v2.4.1 and v2.4.2 no? Because v2.4.2 was the release with vuejs/test-utils@1db42c8 which changed the props() type.

@sawmurai
Copy link
Author

You are right of course :) I'll update the issue.

@sawmurai sawmurai changed the title Bug: Props detection broken with jest since 2.4.3 (works in 2.4.2) Bug: Props detection broken with jest since 2.4.2 (works in 2.4.1) Mar 19, 2024
@cexbrayat
Copy link
Member

@johnsoncodehk would you mind taking a look at why vuejs/test-utils@1db42c8 introduced this regression? How should we type props() to avoid that?

cc @alecgibson as well, as the original author of this change

@alecgibson
Copy link

Weirdly if I download this repro and run locally in VS Code, it seems fine:

Screenshot 2024-03-20 at 14 33 53

npm run build also works fine

@alecgibson
Copy link

It even correctly flags bad props:

Screenshot 2024-03-20 at 14 35 50

and fails npm run build:

❯ npm run build

> [email protected] build
> vue-tsc && vite build

src/components/HelloWorld.spec.ts:14:26 - error TS2339: Property 'foo' does not exist on type '{ readonly msg: string; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | ... 1 more ... | undefined; ... 6 more ...; style?: unknown; } & Partial<...> & Omit<...>'.

14   expect(wrapper.props().foo).toBe('Hello world');
                            ~~~


Found 1 error in src/components/HelloWorld.spec.ts:14

@alecgibson
Copy link

alecgibson commented Mar 20, 2024

Oh I see, npm run build passes, but running jest fails. This feels like a jest misconfiguration, or an issue with the @vue/vue3-jest transformer or its configuration

Edit: or the ts-jest transformer could also be the issue

@cexbrayat
Copy link
Member

Thanks for looking into it @alecgibson !
I'll transfer to the vue-jest repo then, as it does feel like a Jest specific issue 👍

@cexbrayat cexbrayat transferred this issue from vuejs/test-utils Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants