我正在尝试将 Jest 引入我当前的项目。
然而,在初始设置过程中,我遇到了这个错误,并且无法正常运行。
我该如何解决这个问题?
我目前正在使用 vue-cli 中的 vue2。
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'html')
at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:72:44)
at async TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:317:13)
at async runJest (node_modules/@jest/core/build/runJest.js:407:19)
at async _run10000 (node_modules/@jest/core/build/cli/index.js:338:7)
at async runCLI (node_modules/@jest/core/build/cli/index.js:190:3)
这是我的测试代码。
import SettlementProcessing from "@/views/calculate/SettlementProcessing.vue";
import { shallowMount } from "@vue/test-utils";
import Vuetify from "vuetify";
describe("Settlement Component", () => {
let vuetify;
beforeEach(() => {
vuetify = new Vuetify();
});
it("정산 처리 타이틀이 나와야 한다.", () => {
const sc = shallowMount(SettlementProcessing, { vuetify });
expect(true).toBe(true);
});
});
这是我的 package.json。
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/test-utils": "^2.0.0-rc.21",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^28.1.0",
"jest": "^28.1.0",
"vue-cli-plugin-vuetify": "~2.4.0",
"vue-jest": "^3.0.7",
}
这是我的 jest.config.json。
// jest.config.js
module.exports = {
preset: "@vue/cli-plugin-unit-jest",
moduleFileExtensions: [
"js",
"json",
"vue",
],
transform: {
"^[^.]+.vue$": "vue-jest",
"^.+\\.js$": "babel-jest",
},
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1",
},
testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)",
],
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
collectCoverage: false,
collectCoverageFrom: ["**/*.{js,vue}", "!**/node_modules/**"],
};
我该如何解决这个问题?