前提・実現したいこと
vue.jsでjestを使用したテストを書いています(導入部分)
npm run testを実行すると下記のエラーが表示されます。構文に沿ってかけていないのかと予想しています。
エラー
tests/first.test.ts:9:7 - error TS2769: No overload matches this call. The last overload gave the following error. Argument of type '{ propsData: { msg: string; }; }' is not assignable to parameter of type 'FunctionalComponentShallowMountOptions<any>'. Object literal may only specify known properties, and 'propsData' does not exist in type 'FunctionalComponentShallowMountOptions<any>'. 9 propsData: { ~~~~~~~~~~~~ 10 msg: val ~~~~~~~~~~~~~~~~ 11 } ~~~~~~~ node_modules/@vue/test-utils/types/index.d.ts:199:25 199 export declare function shallowMount<V extends Vue, Props = DefaultProps> (component: ExtendedVue<V, {}, {}, {}, Props>, options?: FunctionalComponentShallowMountOptions<V>): Wrapper<CombinedVueInstance<V, {}, {}, {}, Props> & Vue> ~~~~~~~~~~~~ The last overload is declared here. Test Suites: 1 failed, 1 total
該当のソースコード
testts
1import Hello from "../src/components/HelloWorld.vue"; 2import { Wrapper, shallowMount } from '@vue/test-utils' 3// import testrr from "../src/components/Test.vue"; 4describe('greet', (): void => { 5 test('should say hello to Tom.', (): void => { 6 const val = "0に" 7 const wrapper = shallowMount(Hello, { 8 propsData: { 9 msg: val 10 } 11 }); 12 13 expect(wrapper.props().val).toBe(val); 14 expect(wrapper.isVueInstance()).toBeTruthy(); 15 }); 16})
packagejson
1{ 2 "name": "app", 3 "version": "0.1.0", 4 "private": true, 5 "scripts": { 6 "serve": "vue-cli-service serve", 7 "build": "vue-cli-service build", 8 "lint": "vue-cli-service lint", 9 "test": "jest" 10 }, 11 "dependencies": { 12 "core-js": "^3.6.5", 13 "tslib": "^2.2.0", 14 "vue": "^2.6.13" 15 }, 16 "devDependencies": { 17 "@types/jest": "^26.0.23", 18 "@typescript-eslint/eslint-plugin": "^4.26.0", 19 "@typescript-eslint/parser": "^4.26.0", 20 "@vue/cli-plugin-babel": "~4.5.0", 21 "@vue/cli-plugin-eslint": "~4.5.0", 22 "@vue/cli-plugin-typescript": "~4.5.0", 23 "@vue/cli-service": "^4.5.13", 24 "@vue/eslint-config-prettier": "^6.0.0", 25 "@vue/eslint-config-typescript": "^7.0.0", 26 "@vue/test-utils": "^1.2.0", 27 "eslint": "^6.7.2", 28 "eslint-plugin-prettier": "^3.3.1", 29 "eslint-plugin-vue": "^6.2.2", 30 "jest": "^26.6.3", 31 "prettier": "^2.2.1", 32 "ts-jest": "^26.5.0", 33 "typescript": "^4.3.2", 34 "vue-jest": "^3.0.7", 35 "vue-template-compiler": "^2.6.13" 36 }, 37 "jest": { 38 "moduleFileExtensions": [ 39 "ts", 40 "js", 41 "json", 42 "vue" 43 ], 44 "transform": { 45 "^.+\.ts$": "ts-jest" 46 }, 47 "globals": { 48 "ts-jest": { 49 "tsconfig": "tsconfig.json" 50 } 51 }, 52 "testMatch": [ 53 "**/tests/**/*.test.ts" 54 ] 55 } 56} 57
tsconfigjson
1{ 2 "compilerOptions": { 3 "target": "esnext", 4 "module": "esnext", 5 "strict": true, 6 "jsx": "preserve", 7 "importHelpers": true, 8 "moduleResolution": "node", 9 "skipLibCheck": true, 10 "esModuleInterop": true, 11 "allowSyntheticDefaultImports": true, 12 "sourceMap": true, 13 "baseUrl": ".", 14 "types": [ 15 "webpack-env", 16 "jest", 17 ], 18 "paths": { 19 "@/*": [ 20 "src/*" 21 ] 22 }, 23 "lib": [ 24 "esnext", 25 "dom", 26 "dom.iterable", 27 "scripthost" 28 ] 29 }, 30 "include": [ 31 "src/**/*.ts", 32 "src/**/*.tsx", 33 "src/**/*.vue", 34 "tests/**/*.ts", 35 "tests/**/*.tsx" 36 ], 37 "exclude": [ 38 "node_modules" 39 ] 40} 41
HelloWorldvue
1<template> 2 <div class="hello"> 3 <h1>{{ msg }}</h1> 4 </div> 5</template> 6 7<script lang="ts"> 8import Vue from "vue"; 9 10export default Vue.extend({ 11 name: "HelloWorld", 12 props: { 13 msg: String, 14 }, 15}); 16</script>
試したこと
defineComponentを使用してみる
https://github.com/vuejs/vue-test-utils/issues/1781
どなたか知見のある方いましたら、ご教授いただきたいです。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。