-
Notifications
You must be signed in to change notification settings - Fork 246
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
Better types for wrapper.vm
when the component is closed
#972
Comments
@pikax do you have an idea how we could solve that? |
Currently that's not possible, I'm working on this PR vuejs/core#4465 to improve some types, I can have a look on how to also add that info there |
This new option allows a better typechecking of components that expose variables. See vuejs/language-tools#805 Refs vuejs#972 as this partially fixes it
For anyone keeping up with this, @johnsoncodehk released [email protected] with a new option that improves the situation. See #1170 |
This new option allows a better typechecking of components that expose variables. See vuejs/language-tools#805 Refs vuejs#972 as this partially fixes it
This new option allows a better typechecking of components that expose variables. See vuejs/language-tools#805 Refs vuejs#972 as this partially fixes it
The explicit cast solution stops working with the last Vue release (3.2.45). |
@felixzapata are you using VTU v2.2.2 ? There was a breaking change in Vue v3.2.45, but the latest VTU release should work around it. |
sorry, I forgot to mention that with VTU 2.2.2 also fails. I mean, I tested with Vue 3.2.45 and VTU 2.2.2 |
@felixzapata In that case, can you open an issue with a small repro using https://stackblitz.com/edit/vitest-dev-vitest-a961ap?file=package.json&initialPath=__vitest__ please? We'll take a look |
I will try because, besides the standard packages, we have some custom configurations and TypeScript typing rules. I am reviewing the tests that are failing; all the ones we have using casting in order to spy methods. |
Is there a way to allow this mocking? Is similar to this one but the problem I think is because of mount and because I am late setting the mock. I think it should be during the mounting process. |
@felixzapata It is not possible, as this is not possible in vanilla JS. See #1798 (comment) for more explanation. |
ok, maybe I have some thoughts of something similar I did in the past regarding the framework/library. |
This may have been improved for vue-tsc, but it still fails with Volar AFAIK. |
Is there any related issues for vue or volar that we could chime in on since this is an external issue? |
I saw that, however it looks like that has been untouched since 9/2021. The TS version referenced in the package json is a major version behind, so probably safe to say it is stale |
In component:
In test:
Not sure if proper solution, but solves the typing without any casts. |
@ulfgebhardt Thanks, but your solution is expected to work: this issue is for the cases where you don't want to expose the variable. |
This will require a few changes from https://github.com/vuejs/language-tools, since the SFC types are generated by it, I recommend creating a cross issue over there. |
Since
2.0.0-rc.15
, we are now exposing$.proxy
aswrapper.vm
to simplify testing ofscript setup
component,allowing to test the following component:
with
expect(wrapper.vm.count).toBe(0)
, even ifcount
is not exposed by the component (see PR #931 ).This works, but for TS (
vue-tsc
),wrapper.vm
does not have acount
property, becausewrapper.vm
is typed asComponentPublicInstance
.Ideally, we would like
wrapper.vm
type to reflect that it is actually not the component public instance, but the properties exposed to the template. Is there a way to infer that?To reproduce, remove
"exclude": ["tests/expose.spec.ts"]
fromtsconfig.volar.json
, and runyarn vue-tsc
. It fails with:For readers interested in this issue, you can workaround it with an explicit cast:
expect((wrapper.vm as unknown as { count: number }).count).toBe(1)
The text was updated successfully, but these errors were encountered: