我正在嘗試使用
它能夠看到正常的屬性(例如,用defineProps宏定義的屬性)。這只是 VSCode 特定工具的問題,還是我應該用另一種方法來測驗 vue3 組件中的計算屬性?
If this is the preferred method, is there a way to pull in the types of the computed properties (similar to how the types of the defined props seem to be pulled in)?
I have tried the technique described in this 
uj5u.com熱心網友回復:
我假設mount您使用的是來自@vue/test-utils. 您可以像這樣鍵入包裝器以使打字稿自動完成并且沒有錯誤:
import {mount, VueWrapper} from "@vue/test-utils";
import HelloWorld from "@/components/HelloWorld.vue"
import { ComponentPublicInstance } from "vue";
type MyComponentProps = any
type MyComponentVariables = {
hello: string
}
type MyComponentWrapperType = VueWrapper<ComponentPublicInstance<MyComponentProps, MyComponentVariables>>
describe('Hello', () => {
it('should compute hello', () => {
const wrapper: MyComponentWrapperType = mount(HelloWorld);
expect(wrapper.vm.hello).toBe('Hello');
});
});
第一個泛型型別(我放在這里any)是組件的 props 型別,第二個泛型({ bipbip: string })是回傳屬性的型別(在setup函式中回傳的內容)。有了<script setup>你可以直接把你所有的變數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/442216.html
標籤:typescript vue.js vuejs3 vue-test-utils vitest
上一篇:Vue.jsv-model未拾取
