用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/aiskillstore/marketplace --skill tdd-workflow命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | tdd-workflow |
| description | Test-Driven Development methodology for Node.js/TypeScript projects. |
Test-Driven Development methodology for Node.js/TypeScript projects.
Write tests BEFORE implementation:
Make tests pass with minimal code:
Improve code while keeping tests green:
describe('Calculator', () => {
it('should add two numbers correctly', () => {
// Arrange - Set up test conditions
const calculator = createCalculator();
// Act - Execute the behavior
const result = calculator.add(2, 3);
// Assert - Verify the outcome
expect(result).toBe(5);
});
});
Format: should {expectedBehavior} when {scenario}
Examples:
it('should return empty array when input is empty', ...);
it('should throw ValidationError when email is invalid', ...);
it('should emit event when state changes', ...);
describe('validateEmail', () => {
it('should return true for valid email', () => {
expect(validateEmail('user@example.com')).toBe(true);
});
});
describe('UserService', () => {
it('should persist user to database', async () => {
const db = createTestDatabase();
const service = createUserService({ db });
await service.createUser({ email: 'test@example.com' });
const user = await db.users.findFirst();
expect(user.email).toBe('test@example.com');
});
});
describe('API Contract', () => {
it('should return user with expected shape', async () => {
const response = await api.getUser('1');
expect(response).toMatchObject({
id: expect.any(String),
email: expect.any(String),
createdAt: expect.any(Date),
});
});
});
Returns canned data:
const stubApi = {
getUser: () => Promise.resolve({ id: '1', name: 'Test' }),
};
Verifies interactions:
const mockLogger = {
info: jest.fn(),
error: jest.fn(),
};
// Later: expect(mockLogger.info).toHaveBeenCalledWith('message');
Working implementation:
const createFakeDatabase = () => {
const store = new Map();
return {
save: (entity) => store.set(entity.id, entity),
findById: (id) => store.get(id),
};
};
Records calls:
const spy = jest.spyOn(service, 'notify');
await service.process();
expect(spy).toHaveBeenCalledTimes(1);
src/
services/
user-service.ts
user-service.test.ts # Co-located unit tests
api/
handlers.ts
handlers.test.ts
tests/
integration/ # Integration tests
user-flow.test.ts
fixtures/ # Shared test data
users.ts
helpers/ # Test utilities
test-context.ts
// Bad - testing internal state
expect(service._cache.size).toBe(1);
// Good - testing behavior
expect(service.getCachedValue('key')).toBe('value');
// Bad - brittle
expect(result).toEqual({
id: '123',
name: 'Test',
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-01'),
});
// Good - flexible
expect(result).toMatchObject({
id: expect.any(String),
name: 'Test',
});
// Bad - tests depend on order
let user;
it('should create user', () => { user = createUser(); });
it('should update user', () => { updateUser(user); }); // Depends on previous
// Good - independent tests
it('should update user', () => {
const user = createUser();
updateUser(user);
});