一键导入
tdd-workflow
Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | tdd-workflow |
| description | Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development. |
This skill ensures all code development follows TDD principles with comprehensive test coverage.
ALWAYS write tests first, then implement code to make tests pass.
Considering the purpose of the component and the properties it accepts, identify the user journeys it supports and various scenarios that could occur based on its features.
For each scenario or feature, create comprehensive test cases:
import { html } from 'lit';
import { fixture, expect } from '@open-wc/testing';
import './dt-search-component.js';
describe('DT-Search-Component', () => {
it('returns relevant results for query', async () => {
const el = await fixture(html`<dt-search-component></dt-search-component>`);
// Test implementation
// expect(el.results).to.have.lengthOf(5);
})
it('handles empty query gracefully', async () => {
const el = await fixture(html`<dt-search-component query=""></dt-search-component>`);
// Test edge case
})
it('is accessible', async () => {
const el = await fixture(html`<dt-search-component></dt-search-component>`);
await expect(el).shadowDom.to.be.accessible();
})
})
npm test
# Tests should fail - we haven't implemented yet
Write minimal code to make tests pass:
import { LitElement, html } from 'lit';
export class DtSearchComponent extends LitElement {
static properties = {
query: { type: String },
results: { type: Array }
};
render() {
return html`<div>...</div>`;
}
}
customElements.define('dt-search-component', DtSearchComponent);
npm test
# Tests should now pass
Improve code quality while keeping tests green:
// Don't test internal state
expect(component.__count).to.equal(5)
// Test what users see or public API
const input = el.shadowRoot.querySelector('input');
expect(input.value).to.equal('John Doe');
// Breaks easily
const button = el.shadowRoot.querySelector('.css-class-xyz')
// Resilient to changes
const button = el.shadowRoot.querySelector('button[type="submit"]')
const field = el.shadowRoot.querySelector('#main-input')
// Tests depend on each other
let sharedEl;
it('creates user', async () => { sharedEl = await fixture(html`<dt-user></dt-user>`) })
it('updates same user', async () => { /* depends on previous test */ })
// Each test sets up its own data/fixture
it('creates user', async () => {
const el = await fixture(html`<dt-user></dt-user>`)
// Test logic
})
it('updates user', async () => {
const el = await fixture(html`<dt-user></dt-user>`)
// Update logic
})
npm test:watch
# Tests run automatically on file changes
--coverage flag)Remember: Tests are not optional. They are the safety net that enables confident refactoring, rapid development, and production reliability.