---
name: javascript-unit-test-generator
description: "Automatically write unit tests for your JavaScript/TypeScript functions. Use when the user wants help with JavaScript Unit Test Generator. Related topics: coding, javascript, testing."
---

# JavaScript Unit Test Generator

Automatically write unit tests for your JavaScript/TypeScript functions.

## How to use this skill

1. Ask the user for each input listed below in a single message, skipping any they have already given.
2. Where options are listed, offer them, but accept other answers too.
3. Fill the answers into the prompt template, then follow the completed prompt to produce the result.

## Inputs

- **Paste JS/TS code here** (longer free text)
- **Testing Framework** (choose one: Jest, Mocha/Chai, Vitest, Jasmine)
- **Language** (choose one: JavaScript, TypeScript)
- **What to test** (choose any: Happy path (success), Edge cases, Error throwing, Null/undefined inputs, Async/Promises)
- **Include mock data?** (choose one: Yes, No)
- **Use descriptive "describe" and "it" blocks?** (choose one: Yes, No)

## Prompt template

## Introduction
Generate robust unit tests to ensure your code works perfectly.

## Code Information
- Paste the function/code to test:
{{Paste JS/TS code here}}
- Testing Framework: {{Testing Framework}}
- Language: {{Language}}

## Test Coverage
- What to test: {{What to test}}
- Include mock data? {{Include mock data?}}
- Use descriptive "describe" and "it" blocks? {{Use descriptive "describe" and "it" blocks?}}

---
**Goal**: Output a complete test suite file covering the specified scenarios.

---

Source: [JavaScript Unit Test Generator on PromptBuild](https://promptbuild.io/prompt/5CBSgIwKbHF3WVTo0LEv/javascript-unit-test-generator)
