Javascript Testing Patterns
Use when building or repairing JavaScript/TypeScript tests with Jest, Vitest, Testing Library, async services, or CI; select the right test layer, keep mocks contract-aware, and assert public behavior.
Install
npx skills add sandbaseai/workbuddy-skill --skill javascript-testing-patternsgit clone --depth 1 https://github.com/sandbaseai/workbuddy-skill.git /tmp/workbuddy-skill
mkdir -p ~/.claude/skills
cp -r /tmp/workbuddy-skill/skills/javascript-testing-patterns ~/.claude/skills/javascript-testing-patternsPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# JavaScript/TypeScript 测试模式
用 Jest、Vitest 和 Testing Library 建立分层测试:快速单元测试证明纯逻辑,组件/集成测试证明模块协作和协议,少量 E2E 覆盖关键用户旅程。测试应该让失败原因清晰,而不是用大量 snapshot、宽泛 mock 或覆盖率数字制造虚假信心。
## 范围与安全门禁
开始前记录 Node/package manager/runner 版本、目标 revision、需求和不变量、测试环境、外部服务、数据清理、秘密处理和 CI artifact 保留策略。
- 使用合成数据、sandbox 和最小权限账号;不要把 token、cookie、个人数据、环境变量值或完整 URL 写入测试与报告。
- 网络、支付、邮件、队列和数据库使用隔离依赖、fake 或可回滚 fixture;不允许测试默认访问生产。
- 失败截图、DOM、console、网络请求和 coverage 必须脱敏;artifact 访问范围和保留期明确。
- 测试不自动修改实现、关闭 CI 门禁、批准发布或扩大权限;关键环境/清理/副作用未知时返回 `BLOCKED`。
## 测试层选择
| 层级 | 适合验证 | 典型选择 |
| --- | --- | --- |
| Unit | 纯函数、类、解析、业务规则、错误 | Jest/Vitest,无真实网络/数据库 |
| Component | React/Vue 等组件的公开交互和可见状态 | Testing Library + DOM 环境 |
| Integration | API client、模块协作、schema、数据库边界 | MSW/contract harness/隔离依赖 |
| E2E | 登录、结账、关键导航和真实浏览器行为 | Playwright/Cypress,少量高价值路径 |
不要用组件测试断言私有 state,不要用 E2E 覆盖每个分支,也不要把 mock 通过当作真实协议或性能通过。
## AAA 与可读断言
测试名说明场景和结果,结构遵循 Arrange-Act-Assert:
```typescript
it('rejects duplicate email with a conflict error', () => {
const repo = new InMemoryUserRepo();
repo.save({ id: '1', email: 'a@example.test' });
const result = createUser(repo, { email: 'a@example.test' });
expect(result).toMatchObject({ errorCode: 'conflict' });
expect(repo.count()).toBe(1);
});
```
优先断言返回值、错误类型/代码、公开事件、可访问名称、URL 和用户可见文本;不要依赖私有字段、调用顺序或 DOM 层级,除非它们本身是公开契约。
## Fixture、类型与隔离
- 每个测试拥有自己的对象、时间、随机种子、临时目录和数据命名空间;
- `beforeEach`/fixture 只准备必要资源,`afterEach` 无论成功失败都清理并报告清理错误;
- 用工厂函数和明确类型创建数据,避免 `as any` 把无效状态藏起来;Details
- Skill name
javascript-testing-patterns- Repository
- sandbaseai/workbuddy-skill
- Path
skills/javascript-testing-patterns/SKILL.md- License
- MIT
- Repo updated
- 8 September 2026
FAQ
What does the Javascript Testing Patterns skill do?
Use when building or repairing JavaScript/TypeScript tests with Jest, Vitest, Testing Library, async services, or CI; select the right test layer, keep mocks contract-aware, and assert public behavior.
How do I install the Javascript Testing Patterns skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add sandbaseai/workbuddy-skill --skill javascript-testing-patterns. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Javascript Testing Patterns popular?
It lives in sandbaseai/workbuddy-skill, which has 9 GitHub stars and 3 forks.
Related skills
Access Control Security Best Practices
9sandbaseai/workbuddy-skill
Design, review, implement, and verify least-privilege access controls across users, services, tenants, resources, and administrative workflows.
Accessibility Review
9sandbaseai/workbuddy-skill
Use when reviewing a web interface or interaction for semantic, keyboard, focus, screen-reader, ARIA, and contrast accessibility risks.
Acquire Codebase Knowledge
9sandbaseai/workbuddy-skill
Use when the user asks to map, document, or onboard into an existing codebase and needs evidence-backed architecture, structure, conventions, integrations, testing, and concerns documentation.
Playwright Component Testing
9sandbaseai/workbuddy-skill
Design, implement, migrate, and diagnose isolated React or Vue component tests with Playwright and an application-owned story gallery.
Idea Refine
9sandbaseai/workbuddy-skill
Use when a product, feature, content, or workflow idea is vague and needs structured divergent exploration, assumption testing, and convergence into an actionable one-page brief.
Playwright Webapp QA
9sandbaseai/workbuddy-skill
Run browser-based QA for web apps with critical user-flow validation, console and network checks, screenshots, and responsive evidence.
Browse the most popular Claude skills, all testing & qa skills, or write your own with the skills generator.