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: regression on wrapper.vm type in 2.4.0-alpha.0 #2060

Closed
cexbrayat opened this issue May 17, 2023 · 3 comments · Fixed by #2063
Closed

Bug: regression on wrapper.vm type in 2.4.0-alpha.0 #2060

cexbrayat opened this issue May 17, 2023 · 3 comments · Fixed by #2063
Labels
bug Something isn't working

Comments

@cexbrayat
Copy link
Member

Describe the bug

test('mount component', async () => {
  expect(Hello).toBeTruthy();

  const wrapper = mount(Hello, {
    props: {
      count: 4,
    },
  });

  // something does not exist on vm
  expect(wrapper.vm.something).toBe(undefined);
});

To Reproduce
https://stackblitz.com/edit/vitest-dev-vitest-se33u3?file=package.json

The type checking throws in v2.3.2 (as it should because wrapper.vm.something does not exist):

test/basic.test.ts:13:21 - error TS2339: Property 'something' does not exist on type '{ $: ComponentInternalInstance; $data: {}; $props: { readonly count: number; key?: string | number | symbol; ref?: VNodeRef; ref_for?: boolean; ref_key?: string; ... 7 more ...; style?: unknown; }; ... 10 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ...'.

13   expect(wrapper.vm.something).toBe(undefined);

Bump to v2.4.0-alpha.0, and run the command again: the error is now not caught.

npm install && npm run tsc

Expected behavior

The error should be caught in v2.4.0

Related information:

  System:
    OS: Linux 5.0 undefined
    CPU: (2) 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.0-alpha.0 => 2.4.0-alpha.0 
    vitest: latest => 0.31.0 
    vue: latest => 3.3.2 

Additional context

@cexbrayat cexbrayat added the bug Something isn't working label May 17, 2023
@cexbrayat
Copy link
Member Author

@johnsoncodehk What do you think about this?

@johnsoncodehk
Copy link
Member

It seems to be because @vue/test-utils is missing the dependent vue-component-type-helpers module, moving vue-component-type-helpers from devDependencies to dependencies should fix it.

If you need to avoid adding dependencies, copying the code from vue-component-type-helpers is also an option.

@cexbrayat
Copy link
Member Author

It looks like it fixes the issue 👍

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

Successfully merging a pull request may close this issue.

2 participants