Jest testing patterns, factory functions, mocking strategies, and TDD workflow. Use when writing unit tests, creating test factories, or following TDD red-green-refactor cycle.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Jest testing patterns, factory functions, mocking strategies, and TDD workflow. Use when writing unit tests, creating test factories, or following TDD red-green-refactor cycle.
type
skill
created
2026-02-27T00:00:00.000Z
domain
software-development
category
testing
risk
unknown
source
community
tags
["skill","software-development","testing"]
Testing Patterns and Utilities
Testing Philosophy
Test-Driven Development (TDD):
Write failing test FIRST
Implement minimal code to pass
Refactor after green
Never write production code without a failing test
Behavior-Driven Testing:
Test behavior, not implementation
Focus on public APIs and business requirements
Avoid testing implementation details
Use descriptive test names that describe behavior
Factory Pattern:
Create getMockX(overrides?: Partial<X>) functions
Provide sensible defaults
Allow overriding specific properties
Keep tests DRY and maintainable
Test Utilities
Custom Render Function
Create a custom render that wraps components with required providers:
// Element must existexpect(screen.getByText('Hello')).toBeTruthy();
// Element should not existexpect(screen.queryByText('Goodbye')).toBeNull();
// Element appears asynchronouslyawaitwaitFor(() => {
expect(screen.findByText('Loaded')).toBeTruthy();
});