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

Feature request: Better Typing for methods not exposed on vm with Composition API and TypeScript #1458

Closed
ghiscoding opened this issue Apr 27, 2022 · 2 comments

Comments

@ghiscoding
Copy link

Is your feature request related to a problem? Please describe.
I'm starting to add unit tests to a new Vue 3 project with Composition API and I have a lot of problems with the wrapper.vm not showing up my list of methods. After couple of hours of googling and searching through issues in this project, I thought that doing something like await (wrapper.vm as InstanceType<typeof LoginPage>).login() (and I found out that the vm is actually that same type anyway) would help me out but it turns out that it only started to work after exposing the method through defineExpose({ login });, ok great but the thing is that I don't want to revisit and expose these methods simply for the sake of unit testing and typing, I mean sure I could do something like (wrapper.vm as any).login() and I'm good to go but then I lose the typing benefit.

Some similar or related issues found

Describe the solution you'd like
I wish that there would be simpler ways of pulling my list of methods without exposing them (with defineExpose) in Composition API

Describe alternatives you've considered
Well I guess that I have 3 ways that I have found so far for dealing with this

  1. simply cast the wrapper vm to any... (wrapper.vm as any).login()
  2. expose all my methods through defineExpose... defineExpose({ login });
  3. maybe extend the VueWrapper like Bug: Plugins do not extends the VueWrapper type when mounting the wrapper with Typescript #1336 but I haven't tried that and I would find that it's way too much work

in most case I guess that I would go with the easiest which is step 1 but it's really sad to see that I completely lose the benefit of TypeScript typing.

Additional context

@cexbrayat
Copy link
Member

Hi @ghiscoding

Yes we agree with you. This issue is in fact a duplicate of one I created some times ago #972

TL:DR; we're waiting for improvements in Vue itself for now.

I'm going to close this one as a duplicate, please track #972 for updates

@ghiscoding
Copy link
Author

oh ok thanks that didn't come up in my search, thanks for the linking

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

No branches or pull requests

2 participants