Générateur de tests unitaires

VérifiéSûr

Génère des tests unitaires bun:test pour les fichiers TypeScript d'un projet Next.js, couvrant cas nominaux, limites et erreurs, en complétant les tests existants.

Spar Skills Guide Bot
TestingIntermédiaire
2014/09/2026
Claude CodeCursor
#bun-test#nextjs#typescript#unit-tests#test-generation

Recommandé pour

Notre avis

Génère des tests unitaires avec bun:test pour un fichier TypeScript d'un projet Next.js, en complétant un fichier de test existant plutôt qu'en l'écrasant.

Points forts

  • Respecte les conventions du projet : bun:test, fichiers .test.ts/.test.tsx co-localisés à côté de la source
  • Non destructif : lit le fichier de test existant et n'ajoute que les cas manquants (fonctions, branches, scénarios)
  • Couvre le chemin nominal, les cas limites et les erreurs, avec mock des dépendances externes (fetch, store, appels base de données, randomUUID)
  • Adapte l'approche au type de fichier : handler d'API appelé avec des Request simulées, ou logique pure pour les composants React

Limites

  • Limité à la stack Next.js + TypeScript + bun:test ; inutilisable tel quel avec Jest ou Vitest
  • Les tests de composants reposent sur @testing-library/react s'il est disponible, sinon ils se rabattent sur l'extraction de logique pure et la gestion d'événements
  • Ignore volontairement les snapshots et les fichiers structurels (layout.tsx, page.tsx, globals.css), qui restent non couverts
Quand l'utiliser

À utiliser quand vous voulez ajouter rapidement ou compléter des tests unitaires pour un fichier source précis d'un projet Next.js sous Bun.

Quand l'éviter

À éviter sur un projet qui n'utilise pas bun:test ou Next.js, ou lorsque le besoin réel est de la couverture d'intégration ou de bout en bout.

Analyse de sécurité

Sûr
Score qualité88/100

The skill instructs reading source files and writing/updating co-located test files, which is a normal code-generation task. It does not involve destructive commands, network calls, exfiltration, or obfuscation, and does not require powerful tools like bash or docker.

Aucun point d'attention détecté

Exemples

Test a React component
/test components/IssueCard.tsx
Test a Zustand-style store
/test lib/store.ts
Test an API route handler
/test app/api/issues/route.ts

name: test description: Generate unit tests for a file in a Next.js TypeScript project using bun:test. Accepts a file path, reads the source, creates focused tests covering happy path, edge cases, and error scenarios. Checks for an existing test file and only adds missing tests. Follows project conventions (bun:test, co-located .test.ts/.test.tsx files).

Test Generator

Generates unit tests for Next.js TypeScript files using Bun's built-in test runner (bun:test).

Usage

/test components/IssueCard.tsx
/test lib/store.ts
/test app/api/issues/route.ts

The path is relative to the project root (no leading / needed).

Behavior

  1. Accepts a file path — the user provides a path to a source file (e.g., components/IssueCard.tsx)
  2. Resolves the full path — joins the project root with the provided path
  3. Reads the source file — understands the logic, types, dependencies, and patterns
  4. Checks for an existing test file — looks for {basename}.test.ts or {basename}.test.tsx next to the source
  5. If no test file exists — creates one with comprehensive tests
  6. If a test file exists — reads it, determines what's missing (untested functions, branches, scenarios), and adds only the missing test cases (never overwrites)
  7. Writes the test file — co-located beside the source

Test conventions

  • Import from bun:test: import { describe, it, expect, beforeEach, mock, spyOn } from "bun:test"
  • describe blocks to group related tests
  • Clear test names that describe the scenario and expected outcome (e.g., "returns the issue when it exists")
  • Happy path, edge cases, and error scenarios
  • Mock external dependencies: fetch, store, database calls, Next.js response objects
  • Mock crypto.randomUUID() for deterministic IDs in store tests
  • For React components: render with @testing-library/react if available, or keep tests focused on pure logic extraction and event handling
  • For API routes: test request/response behavior by invoking the handler directly with mock Request objects
  • No snapshot testing
  • Use expect().toBe() / toEqual() / toThrow() / toBeNull() / toBeUndefined()

When to skip

  • globals.css, layout.tsx, page.tsx — these are structural bootstrapping files with little testable logic
  • node_modules files
  • Test files themselves (.test.ts / .test.tsx)
Skills similaires