vitest-bdd-3layer
DashPlayer 三层 Vitest-BDD 技能。Use when developers want business-readable BDD scenarios without coupling scenario writing to code implementation details. Triggers on: "BDD 三层", "行为测试分层", "给定当那么", "Vitest BDD", "不想在场景里写实现".
Install
mkdir -p .claude/skills/vitest-bdd-3layer && curl -L -o skill.zip "https://mcp.directory/api/skills/download/4571" && unzip -o skill.zip -d .claude/skills/vitest-bdd-3layer && rm skill.zipInstalls to .claude/skills/vitest-bdd-3layer
About this skill
目的
在 DashPlayer 中用 Vitest + 三层模型 编写 BDD 测试,让“场景编写”与“实现细节”解耦。
目标效果:
- 场景层只写业务句子(给定/当/那么)
- 步骤层维护业务动作词典
- 实现层收敛 mock / fixture / adapter
适用范围
- 业务规则清晰、需要可读验收场景的模块
- service + IPC + renderer 契约验证
- 希望后续可扩展为更多业务域(settings / ai-trans / watch-history)
不适用:
- 纯算法工具函数(普通单测更高效)
- 高波动、易 flaky 的强时序用例
三层目录规范(必须遵守)
以 settings 为例:
-
场景层(Scenario Layer)
src/backend/application/services/__tests__/Xxx.bdd.test.ts- 只能写
given/when/then业务语句 - 禁止直接
new Service、vi.spyOn、store.set/get
-
步骤词典层(Step Dictionary Layer)
src/backend/application/services/__tests__/bdd/xxx.steps.ts- 用英文方法名组织能力:
given* / when* / then* - 场景层仅调用步骤层方法
-
实现层(Fixture/Adapter Layer)
src/backend/application/services/__tests__/bdd/xxx.fixture.ts- 统一管理 mock、fixture、依赖注入与底层调用
工具类约定
复用:src/test/bdd.ts
推荐导入方式(避免 ESM then 命名导出陷阱):
import bdd from '@/test/bdd'
const { scenario, given, when, then } = bdd
标准落地流程
1) 先写场景清单(业务句子)
每条场景必须是一句中文:
给定<前置条件>,当<触发动作>,那么<业务结果>
2) 定义步骤词典方法
使用英文命名,示例:
givenInvalidProviderValues()whenQueryEngineSelection()thenProvidersNormalizedToNone()
规则:
given*只做前置状态准备when*只触发行为then*只做业务结果断言
3) 在实现层补齐 fixture
实现层负责:
- service 实例创建
- store/mock 初始化
- spy 管理(如
fs.existsSync) - 数据读写 helper(
setValue/getValue)
4) 场景层只编排,不实现
场景层示例:
scenario('设置:引擎选择行为', () => {
it('给定 provider 值非法,当查询引擎选择,那么应归一化为 none', async () => {
await given('给定:provider 值非法', () => steps.givenInvalidProviderValues())
await when('当:查询引擎选择', () => steps.whenQueryEngineSelection())
await then('那么:应归一化为 none', () => steps.thenProvidersNormalizedToNone())
})
})
评审清单(8项)
- 场景名是“给定/当/那么”中文句式
- 场景层无技术细节(无 mock/new/spyon)
- 步骤方法命名统一
given/when/then前缀 - 步骤层不堆叠复杂 mock 逻辑
- 实现层集中管理依赖和替身
- Then 断言面向业务结果,不是私有实现
- 场景间状态隔离(beforeEach 重置)
-
yarn test:bdd可通过
常见误用(必须避免)
- 在场景层直接写 mock 或访问 store
- 步骤方法名中英混用(触发命名规则告警)
- 一个场景覆盖多个业务承诺
- 只断言内部调用次数,不断言业务结果
- 步骤层直接包含大量底层构造逻辑(应下沉实现层)
运行命令
yarn test:bdd
yarn test:bdd:watch
扩展建议
- 新业务域按同样三层创建:
xxx.bdd.test.tsbdd/xxx.steps.tsbdd/xxx.fixture.ts
- 优先复用
src/test/bdd.ts,不要重复造 DSL。
More by solidSpoon
View all skills by solidSpoon →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Related MCP Servers
Browse all serversRtfmbro is an MCP server for config management tools—get real-time, version-specific docs from GitHub for Python, Node.j
Integrate DuckDuckGo web search into your site with our MCP server, supporting features like Google custom search and ro
Prisma Postgres offers local and remote MCP servers to simplify database workflows for developers and AI platforms.
Enhance software testing with Playwright MCP: Fast, reliable browser automation, an innovative alternative to Selenium s
Extend your developer tools with GitHub MCP Server for advanced automation, supporting GitHub Student and student packag
Connect Blender to Claude AI for seamless 3D modeling. Use AI 3D model generator tools for faster, intuitive, interactiv
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.