home / skills / shipshitdev / library / testing-expert

This skill helps you design and implement robust testing strategies for React, Next.js, and NestJS applications, improving coverage and reliability.

npx playbooks add skill shipshitdev/library --skill testing-expert

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
2.9 KB
---
name: testing-expert
description: Expert in testing strategies for React, Next.js, and NestJS applications covering unit tests, integration tests, E2E tests, and testing best practices
---

# Testing Expert Skill

Expert in testing strategies for React, Next.js, and NestJS applications.

## When to Use This Skill

- Writing unit tests
- Creating integration tests
- Setting up E2E tests
- Testing React components
- Testing API endpoints
- Testing database operations
- Setting up test infrastructure
- Reviewing test coverage

## Project Context Discovery

1. **Scan Documentation:** Check `.agents/SYSTEM/ARCHITECTURE.md` for testing architecture
2. **Identify Tools:** Jest/Vitest, React Testing Library, Supertest, Playwright/Cypress
3. **Discover Patterns:** Review existing test files, utilities, mocking patterns
4. **Use Project-Specific Skills:** Check for `[project]-testing-expert` skill

## Core Testing Principles

### Testing Pyramid

- **Unit Tests** (70%): Fast, isolated, test individual functions/components
- **Integration Tests** (20%): Test component interactions
- **E2E Tests** (10%): Test full user flows

### Coverage Targets

- Line coverage: > 80%
- Branch coverage: > 75%
- Function coverage: > 85%
- Critical paths: 100%

### Test Organization

```
src/
  users/
    users.controller.ts
    users.controller.spec.ts  # Unit tests
    users.service.ts
    users.service.spec.ts
  __tests__/
    integration/
    e2e/
```

### Test Quality (AAA Pattern)

```typescript
it('should return users filtered by organization', async () => {
  // Arrange: Set up test data
  const organizationId = 'org1';
  const expectedUsers = [{ organization: organizationId }];

  // Act: Execute the code being tested
  const result = await service.findAll(organizationId);

  // Assert: Verify the result
  expect(result).toEqual(expectedUsers);
});
```

## Good Tests Are

- Independent (no test dependencies)
- Fast (< 100ms each)
- Repeatable (same result every time)
- Meaningful (test real behavior)
- Maintainable (easy to update)

## Testing Best Practices Summary

1. **Test Isolation:** Each test independent, clean up after
2. **Meaningful Tests:** Test behavior, not implementation
3. **Mocking Strategy:** Mock external dependencies, not what you're testing
4. **Test Data:** Use factories, keep data minimal, clean up
5. **Coverage:** High coverage, focus on critical paths

## Integration

| Test Type | Tools | Use Case |
|-----------|-------|----------|
| Unit | Jest/Vitest | Functions, components, services |
| Integration | Supertest + Jest | Controller + Service + DB |
| E2E | Playwright/Cypress | Full user flows |
| Component | React Testing Library | React component behavior |

---

**For complete React Testing Library examples, hook testing, Next.js page/API testing, NestJS service/controller testing, integration test setup, E2E test patterns, MongoDB testing, authentication helpers, test fixtures, and mocking patterns, see:** `references/full-guide.md`

Overview

This skill provides expert guidance on testing strategies for React, Next.js, and NestJS applications, covering unit, integration, and end-to-end testing. It focuses on practical patterns, tool selection, and measurable quality targets to make test suites fast, reliable, and maintainable. Use it to design test architecture, write effective tests, and improve coverage on critical paths.

How this skill works

The skill inspects project structure and testing tools to recommend a tailored testing plan: unit tests with Jest or Vitest, component tests with React Testing Library, integration tests using Supertest, and E2E flows with Playwright or Cypress. It reviews existing tests and mocking patterns, suggests file organization and AAA-style examples, and produces actionable changes to meet coverage and speed goals. It also proposes data and cleanup strategies for repeatable tests.

When to use it

  • When adding or refactoring unit tests for components, services, or utilities
  • When building integration tests for controllers, services, and DB interactions
  • When designing E2E test scenarios that verify full user flows
  • When setting test coverage targets and measuring critical-path reliability
  • When establishing project-specific test architecture and tooling choices
  • When reviewing or improving existing test suites for speed and maintainability

Best practices

  • Follow the testing pyramid: mostly unit tests, fewer integration tests, minimal E2E
  • Aim for independent, fast (<100ms), and repeatable tests
  • Mock external dependencies but avoid over-mocking the unit under test
  • Use factories and minimal fixtures; clean up state between tests
  • Organize tests near implementation and separate integration/e2e in __tests__ folders
  • Target line/branch/function coverage thresholds and focus on critical paths

Example use cases

  • Write unit tests for a React hook with React Testing Library and Vitest
  • Create integration tests for a NestJS controller using Supertest and an in-memory DB
  • Implement E2E tests for a Next.js signup flow with Playwright
  • Audit an existing test suite to reduce flakiness and speed up CI runs
  • Design a mocking strategy for external APIs while testing authentication flows

FAQ

What coverage targets should I aim for?

Aim for >80% line coverage, >75% branch coverage, and >85% function coverage, with 100% coverage on critical paths.

How do I keep E2E tests reliable and fast?

Limit E2E to core user flows, mock third-party dependencies where possible, and keep setup/teardown minimal; run full E2E in CI on a schedule and use faster unit/integration tests for most checks.