【发布时间】:2021-07-16 17:03:37
【问题描述】:
我设置了一个 VueJS 2 项目,我正在尝试在其中设置 TypeScript。我正在努力设置我的笑话测试。
我的 ts 组件:
<template>
<div>some template<div>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
});
</script>
服务/构建工作正常。 但我的规范文件(虚拟文件,component.spec.ts):
import { shallowMount} from '@vue/test-utils';
//@ts-ignore
import Form from "@/MyComponent";
describe("Solicitacao Form component", () => {
let wrapper: any;
beforeEach(() => {
wrapper = shallowMount(Form, {
});
})
test('Component created', () => {
expect(wrapper).toBeDefined();
})
})
它总是抛出
测试套件未能运行 Jest 遇到了一个意外的令牌 这 通常意味着您正在尝试导入 Jest 无法导入的文件 解析,例如它不是纯 JavaScript。
我的 jest.config.js 文件
module.exports = {
preset: "@vue/cli-plugin-unit-jest/presets/typescript-and-babel",
//testEnvironment: 'node',
setupFiles: ["<rootDir>/tests/unit/index.js"],
moduleFileExtensions: ["js", "ts", "vue", "json"],
transform: {
".*\\.(vue)$": "vue-jest",
"^.+\\.ts?$": "ts-jest",
"^.+\\.js$": "babel-jest"
},
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1"
},
testMatch: [
"**/tests/unit/**/*.spec.(js|jsx|ts|tsx)"
]
}
知道如何设置笑话吗?
【问题讨论】:
标签: typescript vue.js vuejs2 jestjs