我有一个包含此导入的测试文件:
import { useGlobalStore } from "@stores"
个
路径为src/stores
这在项目中工作正常,但在测试时,我收到以下错误:
Error: Failed to resolve import "@stores" from "src/components/Footer/__test__/Footer.test.tsx". Does the file exist?
个
在之前使用Jest时,我使用modeNameMapper修复了它:
moduleNameMapper: {
"^stores/(.*)$": "<rootDir>/src/stores/$1",
},
我try 根据文档将其添加到Vitest配置中,但没有结果. 这是我的配置文件:
export default defineConfig({
test: {
resolve: {
// ...rest of the code ...
alias: {
// I tried all the commented lines without success
// '@': path.resolve(__dirname, './src'),
// '@': './src',
// '@stores': './src/stores',
// '@/stores': new URL('./src/stores', import.meta.url).pathname,
'@/': new URL('./src/', import.meta.url).pathname,
},
},
},
});
我试了很多东西,但都没有成功.