testing-expert
Expert in testing strategies for React, Next.js, and NestJS applications covering unit tests, integration tests, E2E tests, and testing best practices
What this skill does
# 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/memory/` for durable project context (architecture, deployment, gotchas)
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`
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.