工具

Jest 快速参考

Jest 快速参考 的可打印速查表,适合快速查阅、学习和桌边参考

来源
Jest Documentation (jestjs.io)
许可证
MIT
更新时间
2026-03-27

示例

速查表包含什么

  • 配置
  • 基础测试
  • 断言(Matchers)
  • 异步测试
  • 模拟(Mocking)
  • 间谍(Spies)
  • 快照(Snapshots)
  • Setup & Teardown
  • 配置选项
  • 常见模式

安装

npm install --save-dev jest
# package.json: "scripts": { "test": "jest" }
npx jest              # run all tests
npx jest --watch      # re-run on changes

文件命名

*.test.js测试文件(默认匹配模式)
*.spec.js备用测试文件模式
__tests__/测试目录(自动发现)

运行指定测试

npx jest path/to/file.test.js
npx jest --testNamePattern="adds"
npx jest --verbose     # detailed output

下载完整速查表,获取所有章节的打印排版版本

下载 PDF

下载

选择适合你阅读方式的版本