test-contract
Verify API schemas and contracts match expected format. Validate request/response structures. Use when testing APIs, before integration, or after schema changes.
- License 许可
- MIT
- 所属仓库
- dhaupin/vant
- 最近更新
- 2026-11-13
- Stars
- ★ 16
- Forks
- 1
01 前言 Front Matter
- name
- test-contract
- license
- MIT
- metadata
- { "author": "vant", "version": "1.0" }
- description
- Verify API schemas and contracts match expected format. Validate request/response structures. Use when testing APIs, before integration, or after schema changes.
03 SKILL.md 正文
Test Contract
API schema validation.
When To Use
- API testing
- Before integration
- After schema changes
What To Test
1. Request Schema
const requestSchema = {
type: 'object',
required: ['email', 'password'],
properties: {
email: { type: 'string', format: 'email' },
password: { type: 'string', minLength: 8 }
}
}
2. Response Schema
const responseSchema = {
type: 'object',
required: ['id', 'email'],
properties: {
id: { type: 'string' },
email: { type: 'string' }
}
}
3. Validate
const Ajv = require('ajv')
const ajv = new Ajv()
const validate = ajv.compile(requestSchema)
const valid = validate(requestBody)
Tools
| Tool | Use |
|---|---|
| ajv | JSON Schema validation |
| json-schema-validator | Node validation |
| Swagger/OpenAPI | API spec validation |
Output
## Contract Tests
| Schema | Valid |
|--------|-------|
| Request | [PASS/FAIL] |
| Response | [PASS/FAIL] |
### Errors
- [n] violations
Role: Contract Tester Input: Schema + Data Output: Validation results
04 同仓库更多 Skills
yaml
Data serialization.
vite
Frontend build tool.
typescript
Typed JavaScript.
test-unit
Test individual functions and methods in isolation. Test happy path, edge cases, and error handling. Use when adding new functions, after bug fixes, or before commits.
test-snapshot
Capture and compare UI/component snapshots to detect visual changes. Use when testing UI rendering, before visual changes, or for design systems.
test-smoke
Quick sanity check to verify basic functionality works. Run fastest tests first. Use when needing quick verification before deeper testing.