Skip to content

Jest 配置错误

错误信息

                Jest: 配置错误 — 无效 option in jest.配置.js
              

快速摘要

jest.配置.js or Jest 配置 in 包.JSON 有无效设置, causing Jest 到失败之前运行任何测试.

为什么发生

  • typo in 配置 option name.

  • Using deprecated option 那个是 移除 in newer Jest version.

  • 无效值 类型 for option (e.g., 字符串哪里数组是 expected).

  • Conflicting options 那个能't 是 used together.

最小示例

✗ 错误代码
// jest.config.js
module.exports = {
  testEnviroment: 'jsdom', // typo — should be testEnvironment
};
✓ 修复代码
// jest.config.js
module.exports = {
  testEnvironment: 'jsdom', // correct spelling
};

Fix typo in 配置 option name.

如何诊断

  • 读取错误消息 — Jest 通常 says 哪个 option 是无效.

  • 检查 Jest documentation for 正确 option name and 值类型.

  • Compare 使用 known 工作 Jest 配置.

  • 检查 Jest version — options 可能有 更改之间 versions.

如何修复

  • Fix typo or 无效 option name.

  • 更新到 正确 option name for 你的 Jest version.

  • Fix 值类型 (e.g., use 数组相反的 字符串).

  • 移除 deprecated options and use 它们的 replacements.

如何预防

  • Refer 到 Jest documentation for 你的特定 version.

  • Keep Jest 更新 and 检查迁移指南 for breaking 更改.

  • Use minimal, well-tested 配置 as 开始点.

相关资源

相关术语

相关课程

← 返回语言