Unit Test Generator

VerifiedSafe

Generates bun:test unit tests for Next.js TypeScript files, covering happy path, edge cases, and errors, while extending existing test files.

Sby Skills Guide Bot
TestingIntermediate
9/14/2026
Claude CodeCursor
#bun-test#nextjs#typescript#unit-tests#test-generation

Recommended for

Automated summary

Generates bun:test unit tests for a TypeScript file in a Next.js project, extending an existing test file instead of overwriting it.

Strengths

  • Follows project conventions: bun:test imports and co-located .test.ts/.test.tsx files next to the source
  • Non-destructive: reads the existing test file and only adds missing cases (untested functions, branches, scenarios)
  • Covers happy path, edge cases, and error scenarios, mocking external dependencies such as fetch, store, database calls, and crypto.randomUUID
  • Adapts to the file type: API route handlers invoked directly with mock Request objects, or pure-logic and event-handling tests for React components

Limitations

  • Tied to the Next.js + TypeScript + bun:test stack and not directly usable with Jest or Vitest
  • Component tests depend on @testing-library/react being available and otherwise fall back to testing extracted pure logic
  • Snapshot testing is excluded by design, and structural files (layout.tsx, page.tsx, globals.css) are skipped entirely
When to use it

Use it when you want to quickly add or complete unit tests for a specific source file in a Next.js project running on Bun.

When not to use it

Avoid it on projects that do not use bun:test or Next.js, or when what you actually need is integration or end-to-end coverage.

Security analysis

Safe
Quality score88/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.

No concerns found

How this analysis is made

Examples

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)

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/unit-test-generator-mu0qzp1h' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/unit-test-generator-mu0qzp1h/download' --output '.skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md.part' && mv '.skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md.part' '.skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md' && test -s '.skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/test' && cp -R '.skill-downloads/unit-test-generator-mu0qzp1h' '.claude/skills/test'

Cursor
test -f '.skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md' && test -s '.skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/test' && cp -R '.skill-downloads/unit-test-generator-mu0qzp1h' '.cursor/skills/test'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/unit-test-generator-mu0qzp1h'

openskills read 'unit-test-generator-mu0qzp1h'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/unit-test-generator-mu0qzp1h/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills