test.spec.ts
// test.spec.ts
// import add from "./add";
import { mount } from "@vue/test-utils";
import HelloWorld from "../components/HelloWorld.vue";
describe("test", () => {
it("first", () => {d);
expect(wrapper.text()).toConta
const wrapper = mount(HelloWorlin("Hello world");
});
});
jest.config.js
module.exports = {
roots: ["<rootDir>/src", "<rootDir>/packages", "<rootDir>/test"],
preset: 'ts-jest',
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node'],
transform: {
'^.+\\.vue$': '@vue/vue3-jest', // vue 文件用 vue-jest 转换
'^.+\\.ts$': 'ts-jest', // ts 文件用 ts-jest 转换
'^.+\\js$': 'babel-jest',
},
// 为了修复 Consider using the "jsdom" test environment. 问题
testEnvironment: "jsdom",
collectCoverage: true,
/** 全局 alias */
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1"
},
collectCoverageFrom: [
"**/*.{js,vue}",
"!**/node_modules/**",
"!**/vendor/**",
"!**/coverage/**",
"!**/*.config.*",
"!src/main.js"
],
globals: {
'ts-jest': {
useESM: true,
tsConfig: {
target: 'ES2019'
},
}
}
};