Task Templates
TestingIntermediate15 min
Unit Test Generation
Generate comprehensive unit tests for functions or components with edge case coverage.
testingunit-testscoveragejestvitest
Overview
This template helps you generate thorough unit tests that cover happy paths, edge cases, and error scenarios. It produces tests that follow testing best practices and provide good coverage.
When to Use
Use this when writing tests for new code, improving test coverage for existing code, or learning how to test specific patterns. Works with most JavaScript/TypeScript testing frameworks.
Customize Template
Fill in the variables
Language of the code to test
Which testing framework to use
The function or component code
What does this code do and any dependencies
Any specific testing requirements or focus areas
Examples
Utility Function Tests
Tests for a price calculation utility
Input values:
- language:
- typescript
- test_framework:
- Vitest
- code:
- export function calculatePrice( basePrice: number, quantity: number, discount?: { type: 'percentage' | 'fixed'; value: number } ): number { let total = basePrice * quantity; if (discount) { if (discount.type === 'percentage') { total = total * (1 - discount.value / 100); } else { total = total - discount.value; } } return Math.max(0, Math.round(total * 100) / 100); }
- context:
- Utility function for calculating product prices with optional discounts. Used in the shopping cart and checkout flow.
- test_requirements:
- - Test percentage and fixed discounts - Ensure price never goes negative - Test rounding behavior