JavaScript Unit Test Generator skill for Claude and Codex
A complete test file for your JavaScript or TypeScript function in the framework you use: one describe block per behaviour, happy path, edge cases, error…
Install it once and Claude or Codex runs it for you. When your request matches, your AI loads the skill, asks for anything it is missing, and works through the template itself. Prefer to fill it in by hand? See the full prompt template.
Download the skill (.zip) · View SKILL.md
When it is used
Use when a JavaScript or TypeScript function or module needs a runnable unit test file in Jest, Vitest, Mocha, or Jasmine covering edge cases, errors, and async behaviour. Do not use for end-to-end or browser tests, or test suites in other languages. Related topics: coding, javascript, testing.
What it will ask you for
- Code to test (longer free text)
- Testing framework (choose one: Jest, Vitest, Mocha/Chai, Jasmine, Node test runner)
- Language (choose one: JavaScript, TypeScript)
- Module system (choose one: ES modules, CommonJS)
- External dependencies to mock (free text, e.g. "fetch or a database client or none")
- Scenarios to cover (choose any: Happy path (success), Edge cases, Error throwing, Null/undefined inputs, Async/Promises, Timers and dates)
- Include mock data (choose one: Yes, No)
- Descriptive describe and it blocks (choose one: Yes, No)
How it works
- Extract the contract from the code: inputs, outputs, side effects, thrown errors, and branches, so every test maps to a behaviour.
- Write one describe per public function and one it per behaviour, each named as a readable sentence when descriptive naming is on.
- Cover each selected scenario with specific assertions: boundaries, thrown errors by type or message, null and undefined, awaited promises and rejections.
- Mock only the named external dependencies with the framework's API, reset between tests, and use fake timers for time-dependent code.
- Define fixtures once at the top when mock data is on and output a single file that runs under the framework's default configuration.
What you get
One fenced code block containing the complete test file with imports, fixtures, and describe blocks, followed by the command to run it.
What it watches out for
- Asserting toBeTruthy or toBeDefined where a full equality check would catch a wrong value.
- Mocking the internals of the function under test, which makes the test pass regardless of the implementation.
- Forgetting to await an async expectation, so the test passes before the promise rejects.
- Sharing mutable fixtures between tests without resetting, which makes test order change the results.
How to install
Claude.ai and the Claude desktop app
- Download the skill .zip.
- Open Settings, then Capabilities, and find Skills.
- Choose Upload skill and select the .zip.
- Ask Claude for help with the task. It loads the skill when your request matches.
Claude Code
- Download the skill .zip.
- Unzip it into ~/.claude/skills/ (or .claude/skills/ inside a project).
- Start a new session. Claude Code loads the skill when your request matches.
Codex
- Download the skill .zip.
- Unzip it into ~/.agents/skills/ (or .agents/skills/ inside a project).
- Codex picks it up on its own. Type $ and the skill name to use it, or just ask for the task.
Cursor
- Download the Cursor rule (.mdc).
- Save it in .cursor/rules/ inside your project.
- Cursor's agent applies the rule when your request matches its description.
AGENTS.md (Codex, Cursor, and other coding agents)
- Copy the AGENTS.md section.
- Paste it into AGENTS.md at the root of your repository, creating the file if needed.
- Coding agents that read AGENTS.md follow it when your request fits.