Closed IlCallo closed 5 years ago
Fixed in 0.3.2
@liximomo I upgraded to 0.3.2
.
Hard compilations errors are solved now, tweaking a bit my factories generation code by using ComponentOptions<V>
instead of VueClass<V>
.
Yet, mounting a component like shallowMount(MyComponent)
returns a Wrapper<Vue>
instead of Wrapper<MyComponent>
, which breaks autocomplete capabilities.
I attach my updated code for reference, but the problem is at shallowMount
level, independent from my code scope.
@pikax hey there, I came back to this issue after some months as I'm trying to finish up the work for Quasar Framework jest App Extension, but the same problem as my last post persists: vue-test-utils
mount functions aren't able to infer the underlying Vue instance because VueProxy
doesn't expose it.
Is there a possibility to get this working or shall I just accept there is no way to fix this and hope in Vue 3 better TS support?
Hey @IlCallo,
Can you open a new issue with a reproduction code, a lot of things changed since 0.3.2
, I'm currently doing some v3 stuff so I will most likely mix information if I have a proper look now.
Create a new issue to keep track otherwise this will get lost.
There's plans to improve typings on 2.7.x https://github.com/vuejs/vue/pull/11488 but is still on hold, because if that goes forward it will add a lot of breaking changes.
Checked again, resolved by changing my function types overloads order (VueClass
version must be before ComponentOptions
one).
Works as expected, sorry for bothering
Hi, thank you for the great work!
I have some functions (wrappers for Jest
mount()
helper) which expect aVue
parameter to provide autocomplete for thevm
.Until https://github.com/vuejs/composition-api/commit/ac3581b2eb11f285584fc4ee1279cb2981e7be75, autocomplete didn't worked but at least it didn't fire off any error because the component inerithed from
VueConstructor<never>
and was recognized as aVue
instance.Now I get an error because a lot of
Vue
properties are missing fromVueProxy
(rightfully).I tryed to find a way to make the function work both with
Vue
andVueProxy
(because as a matter of fact I don't really need all the stuff onVue
type,VueProxy
should be enough), but it seems there is noVueClass
equivalent which managesVueProxy
.Also,
VueProxy
itself is not exported and, even if it was, I would have to manually specifyPropsOptions
andRawBindings
instead of having them inferred from the component.Any hint on how to proceed? For the time being I just reverted
VueConstructorProxy
typings in my local setup, but I'd like to solve the problem and make everything work properly.This issue is related to my previous comment here and have the same root cause. Official
mount()
andshallowMount()
testing helpers don't have autocomplete because of theVueProxy
usage.Maybe an helper can be provided which converts back from
VueProxy
to aVue
instance?Bonus: if there is some way to extract props typings from
VueProxy
, I'm interested in that as well.My factory generator functions
```ts import VueCompositionApi from '@vue/composition-api'; import { createLocalVue, shallowMount, VueClass } from '@vue/test-utils'; import { Cookies, Quasar, QuasarPluginOptionsExt } from 'quasar'; import Vue from 'vue'; const mockSsrContext = () => { return { req: { headers: {}, }, res: { setHeader: () => undefined, }, }; }; export const mountQuasar =Usage
```ts import { QBtn, QIcon, QItem, QItemSection, QList } from 'quasar'; import { mountFactory } from 'test/jest/utils'; import MyComponent from './my-component'; const factory = mountFactory(MyComponent, { // Throws error because MyComponent is not of type Vue quasar: { components: { QBtn, QItemSection, QItem, QIcon, QList, }, }, }); describe('MyComponent', () => { it('is a Vue instance', () => { const wrapper = factory({ propName: 'propValue' }); console.log(wrapper.vm.propName); // Even with previous typings, autocomplete for this wouldn't have worked expect(wrapper.isVueInstance()).toBeTruthy(); }); }); ```