Skip to content

Guide · Agent skill

How to use the JavaScript Testing Patterns agent skill

Updated · written with AI from the project's own documentation and checked against our catalogue data

The javascript-testing-patterns skill is a set of written testing guides and example code that an AI agent reads when you ask it to write tests for a JavaScript or TypeScript project. It covers Jest and Vitest setup, unit tests for pure functions and classes, and mocking network calls such as fetch. This guide explains what agent skills are, how to install this one, how to trigger it with plain requests, and what to check before you trust the output.

JavaScript Testing Patternswshobson/agents · MIT

Quick start

  1. 1Download the ZIP. Download the javascript-testing-patterns ZIP from this page.
  2. 2Unzip into a skills folder. Unzip into ~/.claude/skills/ for personal use, or into your project's .claude/skills/ folder for one project.
  3. 3Prepare your project. Make sure Node.js is installed and install Jest or Vitest, plus ts-jest or Testing Library if you plan to use them.
  4. 4Ask for tests in plain language. Name the framework, the language and the file or function you want tested.
  5. 5Review the output. Read the generated test files and mock setup before running them.
  6. 6Run the tests yourself. Use your project's own test command to run the suite and check results.

What this skill makes the agent do

An agent skill is a folder of instructions and reference material that an AI agent loads when a task matches the skill's description. This one is about testing JavaScript and TypeScript code. Its guidance covers setting up Jest or Vitest, structuring unit tests, testing async functions, and mocking external dependencies so tests run without real servers.

The skill is reference material, not a program. It does not run tests or check them for you. The agent reads the patterns and adapts the example code to your project.

  • Sets up Jest (with ts-jest as a preset) or Vitest configuration, including coverage thresholds in the Jest example
  • Shows how to structure unit tests for pure functions and classes with describe, it and expect
  • Shows how to mock global fetch with vi.fn() and test success and failure responses
  • Includes integration testing guidance for APIs, such as supertest with database setup and teardown
  • Covers test-driven development and TDD/BDD workflows

Install the skill: download the ZIP and unzip it

Download the ZIP for this skill from this page. Unzip it so that the skill folder, containing SKILL.md and references/advanced-testing-patterns.md, sits in one of these locations.

For a personal skill available in all your projects, unzip into ~/.claude/skills/. For a skill that only applies to one project, unzip into the project's .claude/skills/ folder.

In the Claude apps you can instead upload the ZIP under Settings → Capabilities → Skills.

  • Personal: ~/.claude/skills/javascript-testing-patterns/
  • Project only: .claude/skills/javascript-testing-patterns/ inside your project

Trigger the skill with natural requests

You do not need a special command. The agent loads the skill when your request matches its description, which mentions writing JavaScript/TypeScript tests, setting up test infrastructure, and TDD/BDD workflows. Name the framework or the thing to test to make the match more likely.

Be specific about your project: say whether you use Jest or Vitest, whether the code is TypeScript, and what the function or class does.

  • "Write Vitest unit tests for the add and divide functions in src/utils/calculator.ts."
  • "Set up Vitest with coverage for this TypeScript project."
  • "Mock fetch in the tests for my ApiService so no real HTTP calls happen."
  • "Help me write the failing test first for a new UserService.create method (TDD)."

Work through an example

The skill's pure-function example shows the typical output. For a calculator with add and divide, the agent writes a test file next to the source file, groups tests with describe, and checks the division-by-zero error with toThrow. The class example does the same for a UserService, using beforeEach to create a fresh instance for each test.

For async code, the skill's pattern replaces global fetch with a mock. Each test sets a resolved value with mockResolvedValueOnce, then checks both the returned data and the URL and options passed to fetch.

  • Read the generated test file before running it, especially the mock setup.
  • Run the tests with your own project's test command. The skill does not run them for you.

What you need before you start

The skill assumes you already have Node.js and a JavaScript or TypeScript project. You install Jest or Vitest yourself, and you also install ts-jest or Testing Library if your setup uses them. The skill does not install packages for you.

  • Node.js and a JavaScript/TypeScript project
  • Jest or Vitest, installed by you
  • ts-jest or Testing Library, only if you use them
  • The skill runs no scripts and uses no network access, according to its metadata

Safety notes and limits

The skill runs no scripts and makes no network calls on its own. The example code, however, shows database setup and teardown in integration tests and SMTP configuration in a mocking example. Read any code the agent generates before running it against a real database or email service.

The skill does not verify that generated tests are correct or complete. A passing test suite only shows that the tests agree with the code as it currently is, so review the assertions yourself.

  • Do not point generated integration tests at a production database.
  • Check that mocks replace real network calls where you intend them to.
  • Review assertions; the skill does not check them for correctness or completeness.

What people use it for

  • Adding Vitest unit tests to a set of pure utility functions in a TypeScript project
  • Testing an existing class such as a service with create, update and delete methods
  • Mocking fetch in an API client so tests run without a live server
  • Setting up a Jest configuration with coverage thresholds for a new TypeScript project
  • Writing a failing test first when following a TDD workflow

Frequently asked questions

How do I install the javascript-testing-patterns skill?

Download the ZIP from this page and unzip it into ~/.claude/skills/ for personal use, or into a project's .claude/skills/ folder. In the Claude apps you can upload the ZIP under Settings → Capabilities → Skills instead.

What do I need to use this skill?

You need Node.js and a JavaScript or TypeScript project. You also need to install Jest or Vitest yourself, plus ts-jest or Testing Library if your setup uses them. The skill does not install these for you.

Is the javascript-testing-patterns skill free?

The skill is published under the MIT licence, as stated on this page. Check the licence file in the source repository for the full terms.

Does the skill run tests for me?

No. The skill is written guidance and example code that the agent reads and adapts. It runs no scripts, and you run your test suite with your own project's tools.

Should I use Jest or Vitest with this skill?

Both are covered. The skill includes a Jest setup with ts-jest and a Vitest setup with v8 coverage. Choose the framework your project already uses, and tell the agent which one you want.

Why do my generated tests fail or look wrong?

The skill does not verify generated tests. Check that your framework and config match the examples, confirm mocks are set up correctly, and read the assertions. Adjust the test to your actual code and run it yourself.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Use this skill if you are starting or extending a JavaScript or TypeScript project and want an agent to write tests in Jest or Vitest, including fetch mocking and coverage setup. Skip it if you only want to run an existing test suite, if your project uses Python or Go, or if you expect the skill to confirm that generated tests are correct.

Download the skill