Prompt file imported from bsdymit/agents-and-agent-accessories (
.github/prompts/add-tests.prompt.md). Copyright stays with the author.
Add Tests
Generate unit tests for a Lambda handler or API client module.
Input Parameters
- file: The source file to write tests for
- framework: jest (TypeScript) or pytest (Python)
What It Does
- Reads the source file to understand exports and dependencies
- Creates a test file in the corresponding
tests/unit/directory - Mocks external dependencies (AWS SDK, API clients, fetch)
- Generates test cases for:
- Happy path (successful execution)
- Error handling (API errors, timeouts)
- Edge cases (empty data, missing fields)
- Input validation
Test Conventions
TypeScript (Jest)
- Test files:
tests/unit/{module}.test.ts - Mock AWS SDK with
jest.mock('@aws-sdk/...') - Mock fetch with
jest.fn()orjest-fetch-mock - Use
describe/itblocks
Python (pytest)
- Test files:
tests/unit/test_{module}.py - Mock with
unittest.mock.patch - Use fixtures for common setup
- Use
pytest.raisesfor error cases
Tips
- Mock at the HTTP/SDK boundary, not at your function level
- Include a test for the rate-limit retry path
- Test with realistic but minimal sample data
- Don't test framework/library behavior — test your logic