【发布时间】:2022-11-09 04:15:28
【问题描述】:
我在下一个 js 项目中使用以下命令安装了 jest
npm i --save-dev jest @testing-library/react @testing-library/jest-dom jest-environment-jsdom
然后使用以下代码添加 jest.config.json 文件
const nextJest = require("next/jest");
const createJestConfig = nextJest({
dir: "./",
});
const customJestConfig = {
moduleDirectories: ["node_modules", "<rootDir>/"],
testEnvironment: "jest-environment-jsdom",
};
module.exports = createJestConfig(customJestConfig);
现在,当我运行“npm test”时,出现以下错误
测试套件无法运行
D:\my-project\node_modules\@jest\reporters\build\GitHubActionsReporter.js:67
#getMessageDetails(failureMessage, config) { ^SyntaxError: 意外的标记 '('
在对象。 (node_modules/@jest/reporters/build/index.js:75:3)
我尝试了很多解决方案,更新配置文件,添加 babel 插件,都没有奏效。而且我还没有在网上找到任何提及此错误的信息。这里有什么问题?
我的开发依赖版本 -
"devDependencies": { "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "eslint": "8.14.0", "eslint-config-next": "12.1.5", "jest": "^29.0.3", "jest-environment-jsdom": "^29.0.3" }
【问题讨论】:
-
你用的是什么版本的节点?
-
是的。谢谢你。我使用的是 14.4.0,切换到最新及以上错误得到解决。
-
是的,使用
#语法的私有方法每个 node.green/#ES2022-features-private-class-methods 至少需要 14.6 个。
标签: javascript next.js jestjs