我对此进行了大量研究,并找到了相当多的解决方案。我已经找到了一种解决方法,并且希望能够正常transform工作transformIgnorePatterns。然而,我唯一能做的似乎就是在我的__mocks__文件夹中手动添加一些模拟模块。
不确定这是否是由于使用Nextjswith引起Jest的?
这是我的jest.config.js
const nextJest = require("next/jest");
const esModules = ["react-markdown", "rehype-raw", "remark-gfm"].join("|");
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
"^@/components/(.*)$": …Run Code Online (Sandbox Code Playgroud)