嗨,我实际上需要在一些 jest 文件中将导出的文件从一个应用程序(commons)导入到其他应用程序(登录),但它没有被 jest 检测到。
笑话测试文件:
import { auth as ServiceAuth } from "@dfs/standard"
import { ContextAlert } from '@dfs/standard';
describe("login page", () => {
it("test case 1", () => {
const ContextAlert = useContext(ContextAlert );
expect(ContextAlert).toBeTruthy()
})
})
错误信息:
FAIL src/Components/LoginPage.test.js ● 测试套件运行失败
Cannot find module '@dfs/standard' from 'LoginPage.test.js'
> 1 | import { auth as ServiceAuth } from "@dfs/standard"
| ^
2 | import { ContextAlert } from '@dfs/standard';
3 |
4 | describe("login page", () => {
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:299:11)
at Object.<anonymous> (src/Components/LoginPage.test.js:1:1)
jest.config.js
module.exports = {
transform: {
"^.+\\.(j|t)sx?$": "babel-jest"
},
moduleNameMapper: {
"\\.(css)$": "identity-obj-proxy",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "identity-
obj-proxy",
}
};
但是该文件正在以相同的语法导入到组件文件中。如何在 jest 测试文件中导入文件?