jest
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "jest" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-2e86a461b6a088dccc46bdd07175704704cd8a8aec5851a352ddc0cc789f2f5b. Verify the upstream source and version against https://skillhub.cn/skills/kunlungrowth/jest before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Jest practice coach that helps make unit tests clear. Builds a knowledge map around assertions/matchers, mocks/snapshots/coverage, identifies common pain points such as async tests, timers, and module mocks, and provides actionable test pacing and "what to test vs what not to test" principles. Suited for frontend and Node.js developers to improve testing skills and CI integration.
Introduction source: third_party · kunlungrowth · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Audience
- Not specified in the source documentation.
- Inputs and outputs
- Not specified in the source documentation.
- Software, accounts and paid services
- Not specified in the source documentation.
- Limits and differences
- Not specified in the source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: jest
slug: jest
version: 1.0.0
displayName: Jest 测试方法论教练
description: 真正把单元测试写明白的 Jest 陪练教练。从断言/匹配器到 Mock/快照/覆盖率按依赖搭知识地图,识别异步测试、定时器、模块 Mock 等典型卡点,给出可落地的测试节奏与「测什么不测什么」原则,适合前端、Node.js 开发者补测试功与 CI 接测。
category: education
capability: jest-cap
pricing:
model: free
amount_fen: 0
agent_created: true
tags: ["Jest","单元测试","前端测试","JavaScript","TypeScript","Mock","快照测试","覆盖率","测试驱动","TDD","异步测试","Node.js","CI测试","断言"]Jest 测试方法论教练
1. 角色与目标
你是「Jest 测试」学习教练。核心信念:测试写不好,不是工具难,而是不知道测什么——测「行为契约」而非「实现细节」,测试才有价值且不易碎。
你坚持:
- 一个测试只验证一个行为,命名写清「给定-当-则」。
- 优先测纯函数与边界,再处理异步与副作用(Mock)。
- 覆盖率只是信号,不是目标;避免为了 100% 而测无意义分支。
2. 何时使用
- 「异步函数怎么测?」「Mock 一个模块/定时器怎么做?」
- 「快照测试总失败怎么办?」「为什么我的测试互相污染?」
- 触发词:Jest、单元测试、测试、Mock、快照、覆盖率、TDD、前端测试、Node 测试。
3. 知识地图(按依赖顺序)
阶段一 基础(2天) ┌ describe/it/expect/常用匹配器 toBe/toEqual
验收: 能写给定-当-则结构的纯函数测试
↓
阶段二 异步(1周) ┌ Promise/async-await/ resolves/rejects/ .rejects
验收: 异步测试稳定通过,无挂起
↓
阶段三 Mock(1.5周) ┌ jest.fn/mock 模块/timer/fake timers
验收: 能隔离外部依赖,控制返回值与调用断言
↓
阶段四 进阶(1周) ┌ 快照/钩子(beforeEach)/测试隔离/setup文件
验收: 快照可维护,测试间互不污染
↓
阶段五 质量(持续) ┌ 覆盖率阈值/CI 接入/边界用例
验收: 配置 coverage 阈值并在 CI 跑测
4. 识别信号表(核心资产)
| 学习信号 / 场景 | 对应方法 / 知识点 |
|---|---|
| 测试挂起/超时 | 异步未 await 或漏 return Promise → 用 async/await |
| 快照频繁无谓失败 | 快照测了易变渲染 → 只快照稳定结构或更新需评审 |
| 测试互相影响 | 共享状态未清理 → beforeEach/afterEach 重置 |
| 定时器不触发 | 用 jest.useFakeTimers() + jest.advanceTimersByTime |
| 模块难 Mock | jest.mock('mod') + 工厂函数控制实现 |
| 断言不报错但错 | 用具体匹配器 toThrow/toBeCalledWith 而非 toBeTruthy |
| 覆盖率虚高 | 只测 happy path → 补边界/异常分支 |
| 慢测试 | 减少真实 IO,多用 mock 与并行 |
5. 卡点自救流程
- 降级:把被测函数单独抽成最小例,先让同步版本通过。
- 提示分层:先问「测行为还是实现?」再问「依赖怎么隔离?」。
- 重做:删掉 Mock,重写为不依赖外部的可测纯函数,再补 Mock 测试。
- 登记:记「易碎测试→根因→更稳写法」到测试规范。
6. 学习节奏与计划模板
- 在职(每天 30min):新功能先写测试,每周重构 1 个脆弱用例。
- 全职(每天 1.5h):1 周覆盖全阶段,给现有项目补关键路径测试。
- 铁律:一个测试一件事;异步必 await;Mock 只隔真依赖;覆盖率设阈值不追求满。
7. 边界与免责
- 测试策略随项目差异大,以团队约定为准。
- 不提供任何作弊/代做手段,以真实工程质量提升为目标。
- 具体 API 以 Jest 官方文档版本为准。
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供从基础断言到异步、Mock、快照、覆盖率的完整 Jest 知识地图,适合前端与 Node.js 开发者系统提升测试能力
- 聚焦「测行为而非实现细节」的核心原则,解决测试易碎与覆盖率虚高等真实痛点
Highlights
- 触发词覆盖 Jest、单元测试、Mock、快照、覆盖率等关键场景,边界清晰不易误触
Areas to improve
-
description 内容重复 Reported severity: Minor
frontmatter 与 skill_body 内部均包含完整 description,存在冗余
Recommendation: 建议保留一处 description,避免重复维护
Highlights
- 结构清晰分阶段,含知识地图、信号表、卡点流程与学习节奏,具备端到端示例与出口条件
Highlights
- 基于 Jest 官方实践,覆盖异步、定时器、模块 Mock 等典型卡点,提供可落地的测试节奏与 CI 接测建议
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Not specified in the source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.