# Jest Unit Testing Prompt A specialized .cursorrules prompt for creating comprehensive unit tests using Jest with TypeScript support. ## What You Can Build - **Unit Test Suites**: Focused tests for critical business logic and utility functions - **Mock-Based Testing**: Tests that properly isolate code from external dependencies - **Data-Driven Tests**: Tests that validate functionality across multiple data scenarios - **TypeScript Testing**: Strongly-typed tests with proper interface definitions - **Edge Case Coverage**: Tests that handle unexpected inputs and boundary conditions ## Benefits - **Proper Dependency Isolation**: Consistent mocking of dependencies before imports - **Complete TypeScript Support**: Full type safety for tested functions and mocked dependencies - **Comprehensive Test Coverage**: Focus on business logic with various data scenarios - **Organized Test Structure**: Logical grouping of tests in descriptive describe blocks - **Edge Case Detection**: Testing for null, undefined, and unexpected types that often cause bugs - **Maintainable Test Suite**: Limited number of focused tests per file for better maintainability ## Synopsis This prompt helps developers create high-quality unit tests with Jest that focus on critical functionality while ensuring proper mocking of dependencies, comprehensive data scenarios, and edge case coverage. ## Overview of .cursorrules Prompt The .cursorrules prompt guides developers in creating effective unit tests using Jest with these key elements: - **TypeScript Detection**: Automatically detects and adapts to TypeScript usage in the project - **Dependency Mocking**: Guidelines for properly mocking dependencies before imports using Jest's mocking functions - **Best Practices**: Eight essential practices for unit testing, including critical functionality focus, data scenarios, and edge cases - **Example Test Patterns**: Provides detailed examples of unit tests in both JavaScript and TypeScript with proper structure - **Maintainable Approach**: Focus on writing a limited number of high-value tests per file - **Test Organization**: Structure tests using describe/it blocks with descriptive names - **AAA Pattern**: Examples using the Arrange-Act-Assert pattern for clear test structure