Agent skill

Writing Unit Tests Typescript

by microsoft-foundry in microsoft-foundry/foundry-agent-webapp

Guidelines and patterns for writing unit tests in TypeScript using Vitest.

MITAuto-check passedTesting & QA

Install Writing Unit Tests Typescript

skills CLI
$ npx skills add microsoft-foundry/foundry-agent-webapp --skill writing-unit-tests-typescript -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install microsoft-foundry/foundry-agent-webapp writing-unit-tests-typescript --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/microsoft-foundry/foundry-agent-webapp.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/writing-unit-tests-typescript .claude/skills/writing-unit-tests-typescript && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
writing-unit-tests-typescript
GitHub stars
127
Token cost
~1.5k tokens
SKILL.md length
228 words
Files
1
Skills in repo
19
Repo updated
First seen
Licence
MIT

At a glance

Guidelines and patterns for writing unit tests in TypeScript using Vitest.

  • Tasks that involve Unit testing
  • SKILL.md covers Overview, Project Structure, Configuration and Test Anatomy, plus 7 more sections
  • Calls npm and npx

What it does

Writing Unit Tests Typescript is an agent skill from microsoft-foundry/foundry-agent-webapp. Guidelines and patterns for writing unit tests in TypeScript using Vitest.

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Testing & QA, covering Unit testing. It works with TypeScript, Vitest and npm. The repository describes itself as: GitHub Copilot enabled repo for building and deploying a web application with Entra ID authentication and integrated with Azure AI Foundry Agents. The licence is MIT.

When your agent uses it

  • Tasks that involve Unit testing

Example prompts

  • “Use the writing-unit-tests-typescript skill to guideline and patterns for writing unit tests in TypeScript using Vitest”
  • “/writing-unit-tests-typescript”

Requirements

  • Node.js

What it can do on your machine

Read from SKILL.md and the folder at commit f6cb362. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npm
    • npx

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npm and npx, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Writing Unit Tests Typescript loads about 1.5k tokens when it runs. Until then it costs about 26 tokens; SKILL.md has 228 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~26
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from microsoft-foundry/foundry-agent-webapp at commit f6cb362, republished under its MIT licence (© microsoft-foundry). 228 words, ~1,509 tokens.

Download SKILL.mdSave it as .claude/skills/writing-unit-tests-typescript/SKILL.md (or your agent's skills folder).
name
writing-unit-tests-typescript
description
Guidelines and patterns for writing unit tests in TypeScript using Vitest.

Skill: Writing TypeScript Unit Tests

Overview

This skill covers writing unit tests for the frontend using Vitest.

Project Structure

text
frontend/
├── package.json          # vitest + jsdom devDependencies
├── vite.config.ts        # Vitest config inline
└── src/
    ├── config/
    │   └── __tests__/
    │       └── authConfig.test.ts
    ├── utils/
    │   ├── citationParser.ts
    │   ├── sseParser.ts
    │   ├── fileAttachments.ts
    │   └── __tests__/
    │       ├── citationParser.test.ts
    │       ├── sseParser.test.ts
    │       └── fileAttachments.test.ts
    ├── services/
    │   └── __tests__/
    │       └── chatService.test.ts
    └── reducers/
        ├── appReducer.ts
        └── __tests__/
            └── appReducer.test.ts    # Includes state shape snapshot

Configuration

The Vitest config lives inline in vite.config.ts:

typescript
export default defineConfig({
  // ... existing config
  test: {
    globals: true,
    environment: "jsdom",
    include: ["src/**/*.test.{ts,tsx}"],
  },
});

Test Anatomy

typescript
import { describe, it, expect } from "vitest";
import { parseCitations, deduplicateAnnotations } from "../citationParser";

describe("citationParser", () => {
  describe("parseCitations", () => {
    it("returns empty array for empty input", () => {
      expect(parseCitations("", [])).toEqual([]);
    });

    it("extracts citation markers from text", () => {
      const text = "Hello [1] world [2]";
      const result = parseCitations(text, annotations);
      expect(result).toHaveLength(2);
    });
  });

  describe("deduplicateAnnotations", () => {
    it("removes duplicate annotations by URL", () => {
      const annotations = [
        { url: "https://example.com", title: "Example" },
        { url: "https://example.com", title: "Example Duplicate" },
      ];
      expect(deduplicateAnnotations(annotations)).toHaveLength(1);
    });
  });
});

Running Tests

powershell
# Run tests in watch mode (interactive)
cd frontend
npm test

# Run tests once (CI mode)
npm run test:run

# Run with coverage
npm run test:coverage

# Run specific file
npx vitest run src/utils/__tests__/citationParser.test.ts

# Run tests matching pattern
npx vitest run --testNamePattern="parseCitations"

Testable Units in This Project

Utils (Pure Functions - Easy to Test)
FileFunctions to Test
citationParser.tsparseContentWithCitations
sseParser.tsparseSseLine, splitSseBuffer
fileAttachments.tsvalidateFile, validateImageFile, validateDocumentFile, validateFileCount, getEffectiveMimeType, convertFilesToDataUris
errorHandler.tsgetUserFriendlyMessage, createAppError, getErrorCodeFromResponse, parseErrorFromResponse, getErrorCodeFromMessage, isTokenExpiredError, isNetworkError, retryWithBackoff
Reducers (Pure Functions - Easy to Test)
FileWhat to Test
appReducer.tsAll action types, state transitions, immutability
Components (Require React Testing Library)

For component testing, add @testing-library/react only when needed:

typescript
import { render, screen } from "@testing-library/react";
import { ChatMessage } from "../ChatMessage";

it("renders message content", () => {
  render(<ChatMessage role="user" content="Hello" />);
  expect(screen.getByText("Hello")).toBeInTheDocument();
});

Assertions Reference

Vitest uses Chai-style assertions via expect:

typescript
// Equality
expect(actual).toBe(expected);           // strict equality (===)
expect(actual).toEqual(expected);        // deep equality

// Truthiness
expect(value).toBeTruthy();
expect(value).toBeFalsy();
expect(value).toBeNull();
expect(value).toBeUndefined();

// Numbers
expect(num).toBeGreaterThan(5);
expect(num).toBeLessThanOrEqual(10);

// Strings
expect(str).toContain("substring");
expect(str).toMatch(/regex/);

// Arrays
expect(arr).toHaveLength(3);
expect(arr).toContain(item);

// Objects
expect(obj).toHaveProperty("key");
expect(obj).toMatchObject({ partial: "match" });

// Exceptions
expect(() => throwingFn()).toThrow();
expect(() => throwingFn()).toThrowError("message");

// Async
await expect(asyncFn()).resolves.toBe(value);
await expect(asyncFn()).rejects.toThrow();

Test Organization

Use describe blocks to group related tests:

typescript
describe("moduleName", () => {
  describe("functionName", () => {
    it("handles normal case", () => {});
    it("handles edge case", () => {});
    it("throws on invalid input", () => {});
  });
});

State Shape Snapshot Tests

Use state shape snapshots to prevent accidental state changes from going unnoticed. If a new field is added to AppState without updating the test, it fails:

typescript
it('should have expected state shape (update this test when adding new state fields)', () => {
  const shape = JSON.stringify(Object.keys(initialAppState).sort());
  expect(shape).toBe('["auth","chat","conversations","ui"]');
  const convShape = JSON.stringify(Object.keys(initialAppState.conversations).sort());
  expect(convShape).toBe('["hasMore","isLoading","list","sidebarOpen"]');
});

This forces anyone adding state fields to also add test coverage — the test file becomes the registry of all state. Apply this pattern to any new top-level state domain.

When Unit Tests Aren't Enough

Use the validating-ui-features skill and Playwright when:

  • Testing requires browser interaction (clicking, navigation)
  • Testing authentication flows with MSAL
  • Testing SSE streaming with real backend
  • Visual regression testing

Quick Reference

CommandPurpose
npm testWatch mode
npm run test:runRun once
npm run test:coverageWith coverage
npx vitest --uiInteractive UI

© microsoft-foundry, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/writing-unit-tests-typescript of microsoft-foundry/foundry-agent-webapp.

Open the folder on GitHubat commit f6cb362

Compare with similar skills

Writing Unit Tests Typescript next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Writing Unit Tests Typescript compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Writing Unit Tests Typescript this skillmicrosoft-foundry/foundry-agent-webapp127—~1.5kAutomated safety check: PassMIT
Npx CLIjwynia/agent-skills165—~2.4kAutomated safety check: PassNone
Create Saleor Packagesaleor/apps162—~608Automated safety check: PassCustom licence
npm Packagejwynia/agent-skills165—~2.1kAutomated safety check: PassNone
Test Writing WorkflowiOfficeAI/AionUi33k1 repos~1.2kAutomated safety check: PassApache-2.0
Creating A Packagec15t/c15t1.9k—~913Automated safety check: PassApache-2.0

Similar skills

  • Npx CLI

    jwynia/agent-skills

    Build and publish npx-executable CLI tools using Bun as the primary toolchain with npm-compatible output.

    165 GitHub stars~2.4k tokensUpdated 7 mo ago
    DevelopmentAuto-check passed
  • Scaffold a new shared package in the saleor-apps monorepo under ./packages/.

    162 GitHub stars~608 tokensUpdated 6 days ago
    DevelopmentAuto-check passed
  • npm Package

    jwynia/agent-skills

    Build and publish npm packages using Bun as the primary toolchain with npm-compatible output.

    165 GitHub stars~2.1k tokensUpdated 7 mo ago
    DevelopmentAuto-check passed
  • Test Writing Workflow

    iOfficeAI/AionUi

    Sets the test-writing workflow for the repository: risk-first scenario lists, behavior-focused Vitest tests, a full run before each commit and a coverage target.

    33k GitHub starsUsed in 1 repo~1.2k tokens
    Testing & QAAuto-check passed
  • Scaffold a new workspace package in the c15t monorepo. An agent skill from c15t/c15t.

    1.9k GitHub stars~913 tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Svelte Testing

    spences10/sveltest

    Fix and create Svelte 5 tests with vitest-browser-svelte and Playwright.

    113 GitHub stars~579 tokensUpdated yesterday
    Testing & QAAuto-check passed

More from microsoft-foundry/foundry-agent-webapp

All 19 skills in this repo
  • Committing Code

    microsoft-foundry/foundry-agent-webapp

    Provides commit message format and workflow for this repository.

    127 GitHub stars~512 tokensUpdated 5 mo ago
    Auto-check passed
  • Implementing Chat Streaming

    microsoft-foundry/foundry-agent-webapp

    Provides SSE streaming patterns for the chat API and frontend.

    127 GitHub stars~1.9k tokensUpdated 5 mo ago
    Auto-check passed
  • Planning Features

    microsoft-foundry/foundry-agent-webapp

    Provides structured plan template for feature implementation.

    127 GitHub stars~548 tokensUpdated 5 mo ago
    Auto-check passed
  • Researching Azure AI SDK

    microsoft-foundry/foundry-agent-webapp

    Provides research patterns for Foundry Agent Service SDK. An agent skill from microsoft-foundry/foundry-agent-webapp.

    127 GitHub stars~4.7k tokensUpdated 5 mo ago
    Auto-check passed
  • Deploying To Azure

    microsoft-foundry/foundry-agent-webapp

    Provides deployment commands and troubleshooting for Azure Container Apps.

    127 GitHub stars~2.2k tokensUpdated 5 mo ago
    Auto-check: warnings
  • Syncing MCP Servers

    microsoft-foundry/foundry-agent-webapp

    Synchronize MCP server configuration between VS Code (.vscode/mcp.json) and Copilot CLI (~/.copilot/mcp-config.json).

    127 GitHub stars~1.3k tokensUpdated 5 mo ago
    Auto-check passed

Categories

Questions about Writing Unit Tests Typescript

What does Writing Unit Tests Typescript do?

Guidelines and patterns for writing unit tests in TypeScript using Vitest. Writing Unit Tests Typescript is an agent skill from microsoft-foundry/foundry-agent-webapp. Guidelines and patterns for writing unit tests in TypeScript using Vitest.

When should I use Writing Unit Tests Typescript?

Writing Unit Tests Typescript fits situations like: tasks that involve Unit testing.

How do I install Writing Unit Tests Typescript in Claude Code?

Run `npx skills add microsoft-foundry/foundry-agent-webapp --skill writing-unit-tests-typescript -a claude-code`. Or copy the skill folder (.github/skills/writing-unit-tests-typescript in microsoft-foundry/foundry-agent-webapp) into .claude/skills/writing-unit-tests-typescript in your project. Claude Code loads it when a task matches its description.

How do I install Writing Unit Tests Typescript in Codex?

Run `npx skills add microsoft-foundry/foundry-agent-webapp --skill writing-unit-tests-typescript -a codex`. Or copy the skill folder (.github/skills/writing-unit-tests-typescript in microsoft-foundry/foundry-agent-webapp) into .agents/skills/writing-unit-tests-typescript in your project. Codex loads it when a task matches its description.

Can I use Writing Unit Tests Typescript in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add microsoft-foundry/foundry-agent-webapp --skill writing-unit-tests-typescript -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/writing-unit-tests-typescript, .gemini/skills/writing-unit-tests-typescript, .github/skills/writing-unit-tests-typescript and .opencode/skills/writing-unit-tests-typescript in your project.

What does Writing Unit Tests Typescript need to run?

Going by SKILL.md and its folder, Writing Unit Tests Typescript needs the command-line tools its instructions call (npm and npx). Our summary lists: Node.js.

Does Writing Unit Tests Typescript access the network?

SKILL.md contains no URLs. Its commands use npm and npx, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Writing Unit Tests Typescript safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Writing Unit Tests Typescript use?

Writing Unit Tests Typescript is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Writing Unit Tests Typescript use?

About 1.5k tokens (SKILL.md is roughly 6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Writing Unit Tests Typescript?

Skills that share tags, products or a category with Writing Unit Tests Typescript: Npx CLI (jwynia/agent-skills, 165 stars), Create Saleor Package (saleor/apps, 162 stars), npm Package (jwynia/agent-skills, 165 stars) and Test Writing Workflow (iOfficeAI/AionUi, 33k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Writing Unit Tests Typescript?

microsoft-foundry (a GitHub organization) maintains it in microsoft-foundry/foundry-agent-webapp, which has 127 GitHub stars. The repository holds 19 skills in this directory. The repository was last updated on April 21, 2026.

Source: microsoft-foundry/foundry-agent-webapp on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.