doox911 Asked:2021-12-09 20:29:10 +0000 UTC2021-12-09 20:29:10 +0000 UTC 2021-12-09 20:29:10 +0000 UTC Jest 看不到通过别名(别名)连接的模块、常量 772 该项目使用vue cli. 在测试文件中,我使用别名包含模块。vue.config.js我在和中注册了别名tsconfig.json。它们在项目中的任何地方工作,除了带有测试的文件。可能是什么问题呢? vue.js 1 个回答 Voted Best Answer doox911 2021-12-09T20:29:10Z2021-12-09T20:29:10Z Jest有自己的配置文件 - jest.config.js. 为了让Jest看到您的别名,您需要在moduleNameMapper. 例子: module.exports = { preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel', setupFiles: ['./tests/setup.js'], 'moduleNameMapper': { '^Api(.*)': '<rootDir>/src/api/$1', '^Components(.*)': '<rootDir>/src/components/$1', '^Constants(.*)': '<rootDir>/src/constants/$1', '^UserComponents(.*)': '<rootDir>/src/components/auth/user/$1', '^Exception(.*)': '<rootDir>/src/exceptions/$1', '^Helpers(.*)': '<rootDir>/src/helpers/$1', '^Mixins(.*)': '<rootDir>/src/mixins/$1', '^Plugins(.*)': '<rootDir>/src/plugins/$1', '^Router(.*)': '<rootDir>/src/router/$1', '^Rules(.*)': '<rootDir>/src/rules/$1', '^Store(.*)': '<rootDir>/src/store/$1', '^Types(.*)': '<rootDir>/src/types/$1', '^Views(.*)': '<rootDir>/src/views/$1', } }; 协会。
Jest有自己的配置文件 -
jest.config.js. 为了让Jest看到您的别名,您需要在moduleNameMapper.例子:
协会。