Skip to content
Back to skills

Testing Typescript

ASecurity

Writes tests following TDD (using vitest and @testing-library/react) best practices. Use when writing unit tests, integration tests, or component tests in TypeScript.

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
ai-agentstypescriptbashreacttestingdocumentation

Works with

  • claude code
  • cli

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 25, 2026

npx -y skills add qte77/claude-code-plugins --skill testing-typescript --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Testing Typescript?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Testing Typescript
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qte77-testing-typescript/badge)](https://www.skillsdirectory.com/skills/qte77-testing-typescript)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: testing-typescript
description: Writes tests following TDD (using vitest and @testing-library/react) best practices. Use when writing unit tests, integration tests, or component tests in TypeScript.
compatibility: Designed for Claude Code
metadata:
  allowed-tools: Read, Grep, Glob, Edit, Write, Bash
  argument-hint: [test-scope or component-name]
  stability: stable
  content-hash: sha256:9d120f8a107caa25d18f6a308f85fb8ddaf7d09c4b57c3b62d2c414fba14c6cf
---

# TypeScript Testing

**Target**: $ARGUMENTS

Writes **focused, behavior-driven tests** following project testing strategy.

## Quick Reference

**TDD methodology** (language-agnostic): See `tdd-core` plugin (`testing-tdd` skill)

**TypeScript-specific documentation**: `references/`

- `references/testing-strategy-ts.md` — TypeScript tools (vitest, @testing-library/react, MSW)
- `references/tdd-best-practices-ts.md` — TypeScript TDD examples (extends tdd-core)

## Quick Decision

**vitest (default)**: Use `it`/`test` for known cases, `vi.mock` for module mocking. Works at unit/integration levels.

**@testing-library/react (components)**: Use for React component behavior testing with render, screen, userEvent.

See `references/testing-strategy-ts.md` for full methodology comparison.

## TDD Essentials (Quick Reference)

**Cycle**: RED (failing test / type error) -> GREEN (minimal pass) -> REFACTOR (clean up)

**Structure**: Arrange-Act-Assert (AAA)

```typescript
it('calculates order total from item prices', () => {
  // ARRANGE
  const items = [{ price: 10, qty: 2 }, { price: 5, qty: 1 }];
  const calculator = new OrderCalculator();

  // ACT
  const total = calculator.total(items);

  // ASSERT
  expect(total).toBe(25);
});
```

## Component Testing Priorities

| Priority | Area | Example |
| -------- | ---- | ------- |
| CRITICAL | User interactions | Button click triggers handler |
| CRITICAL | Conditional rendering | Error state shows message |
| HIGH | Form validation | Invalid input shows error |
| HIGH | Async data loading | Loading -> success/error states |

## What to Test (KISS/DRY/YAGNI)

**High-Value**: Business logic, error paths, component behavior, async flows, custom hooks

**Avoid**: Type system behavior, library internals, CSS styling, implementation details

See `references/testing-strategy-ts.md` -> "Patterns to Remove" for full list.

## Naming Convention

**Format**: `{module} > {component} > {behavior}`

```typescript
describe('UserService', () => {
  it('creates a new user with valid data', () => { ... });
  it('rejects duplicate email addresses', () => { ... });
});
```

## Execution

```bash
npx vitest                          # Watch mode (default)
npx vitest run                      # Single run
npx vitest run src/utils            # Filter by path
npx vitest run --reporter=verbose   # Verbose output
npx vitest --ui                     # Browser UI
```

## Quality Gates

- [ ] All tests pass (`npx vitest run`)
- [ ] TDD Red-Green-Refactor followed
- [ ] Arrange-Act-Assert structure used
- [ ] Naming convention followed
- [ ] Behavior-focused (not implementation)
- [ ] No library/framework behavior tested
- [ ] Mocks use `vi.mock()` with proper restore (`vi.restoreAllMocks()`)

Files in this skill

  • SKILL.md3.1 KB
  • references/tdd-best-practices-ts.md3.7 KB
  • references/testing-strategy-ts.md5.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.