Logo vun Test Write

Test Write

Communautéit
kazdenc
test-write

Generate tests for existing code including unit, integration, and e2e tests. Uses Vitest and Testing Library by default. Use when user says "write tests", "add tests", "test this function", "test this component", "need test coverage", or wants tests written for existing code.

Iwwersiicht

Editeurkazdenc
Repositorybuilder-skills
Skill-Nummtest-write
Stären
46
Forks
5
Matgeliwwert Fichieren
Nëmmen Instruktiounen
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum kazdenc op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Test Write an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/kazdenc/builder-skills/tree/main/.claude/skills/dev/test/test-write
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/kazdenc/builder-skills.git /tmp/builder-skills
mkdir -p .claude/skills
cp -r /tmp/builder-skills/.claude/skills/dev/test/test-write .claude/skills/test-write
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Test Write an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Test Write automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Test Write net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Write Tests

Generate tests that catch real bugs and survive refactors. Every test should answer: what behavior breaks if this test fails?

Step 1: Read the Code

Before writing any test, understand the code under test. If the user provides a file or function, read it first.

What to identifyWhy it mattersWatch out for
InputsThese become your test parametersAssuming only happy-path inputs
Outputs / return valuesThese are your assertionsTesting internal state instead of outputs
Side effectsThese need mocking or verificationMissing async side effects, event emissions
Edge casesThese are where bugs hidenull, undefined, empty arrays, boundary values, concurrent calls
Error pathsThese need explicit test coverageOnly testing success cases

Step 2: Determine Test Type

Match the code to the right kind of test.

Code under testTest typeTools
Pure function (util, helper, transformer)Unit testVitest
React componentComponent testVitest + @testing-library/react + @testing-library/user-event
React hookHook testVitest + @testing-library/react (renderHook)
API route / server handlerIntegration testVitest + supertest or direct handler invocation
Full user flow (multi-page, auth)E2E testPlaywright
Redux / Zustand storeUnit testVitest

Step 3: Write Tests Using the AAA Pattern

Structure every test as Arrange, Act, Assert. This keeps tests readable and intention-revealing.

typescript
describe('functionName', () => {
  it('should [expected behavior] when [condition]', () => {
    // Arrange — set up inputs and dependencies
    const input = { name: 'test', value: 42 };

    // Act — call the code under test
    const result = functionName(input);

    // Assert — verify the output
    expect(result).toEqual({ processed: true, name: 'test' });
  });
});

Test Naming Convention

Use describe for the unit, it for the behavior. Name tests so a failure message reads like a sentence.

describe('calculateTotal')
  it('should return 0 when cart is empty')
  it('should sum item prices including quantity')
  it('should apply percentage discount to subtotal')
  it('should throw when discount exceeds 100%')

Common Test Patterns

Testing Async Functions

typescript
it('should resolve with user data when API call succeeds', async () => {
  const user = await fetchUser('user-123');
  expect(user).toEqual({ id: 'user-123', name: 'Test' });
});

it('should reject when user is not found', async () => {
  await expect(fetchUser('nonexistent')).rejects.toThrow('User not found');
});

Testing React Hooks

typescript
import { renderHook, act } from '@testing-library/react';

it('should increment counter', () => {
  const { result } = renderHook(() => useCounter(0));

  act(() => {
    result.current.increment();
  });

  expect(result.current.count).toBe(1);
});

Testing React Components

typescript
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

it('should submit form with entered values', async () => {
  const onSubmit = vi.fn();
  const user = userEvent.setup();
  render(<LoginForm onSubmit={onSubmit} />);

  await user.type(screen.getByLabelText('Email'), 'test@example.com');
  await user.type(screen.getByLabelText('Password'), 'password123');
  await user.click(screen.getByRole('button', { name: 'Log in' }));

  expect(onSubmit).toHaveBeenCalledWith({
    email: 'test@example.com',
    password: 'password123',
  });
});

Testing Components with Async State

typescript
import { render, screen, waitFor } from '@testing-library/react';

it('should display user name after loading', async () => {
  render(<UserProfile userId="123" />);

  expect(screen.getByText('Loading...')).toBeInTheDocument();

  await waitFor(() => {
    expect(screen.getByText('Jane Doe')).toBeInTheDocument();
  });
});

Testing API Routes (with mocking)

typescript
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';

const server = setupServer(
  http.get('/api/users/:id', ({ params }) => {
    return HttpResponse.json({ id: params.id, name: 'Test User' });
  })
);

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it('should handle API error gracefully', async () => {
  server.use(
    http.get('/api/users/:id', () => {
      return new HttpResponse(null, { status: 500 });
    })
  );

  render(<UserProfile userId="123" />);

  await waitFor(() => {
    expect(screen.getByText('Failed to load user')).toBeInTheDocument();
  });
});

Testing Error Cases

typescript
it('should throw TypeError when input is null', () => {
  expect(() => processData(null)).toThrow(TypeError);
});

it('should render error boundary fallback on component error', () => {
  const BrokenComponent = () => { throw new Error('boom'); };

  render(
    <ErrorBoundary fallback={<p>Something went wrong</p>}>
      <BrokenComponent />
    </ErrorBoundary>
  );

  expect(screen.getByText('Something went wrong')).toBeInTheDocument();
});

Edge Cases to Always Consider

Include these in every test suite. They catch the bugs that slip past happy-path testing.

Edge caseExample test
null / undefined inputsprocessData(null) — should throw or return default
Empty arrays / objectscalculateTotal([]) — should return 0, not NaN
Boundary valuespaginate(items, { page: 0 }) — zero, negative, max int
Concurrent callsTwo rapid clicks on submit — should not double-submit
Large inputs10,000-item array — should not crash or hang
Unicode / special characterssearch('caf\u00e9') — should handle diacritics
Type coercion trapscompare('1', 1) — should use strict equality

Code Conventions

ConventionRationale
One assertion per test (when practical)Pinpoints exactly what failed. Use multiple asserts only when they verify one logical behavior.
No test interdependencyEvery test must pass in isolation. Never rely on execution order or shared mutable state.
Use factories, not fixturescreateUser({ name: 'Test' }) is flexible. fixtures/user.json is rigid and hides intent.
Colocate tests with sourceutils.ts and utils.test.ts in the same directory. Easy to find, easy to maintain.
Use vi.fn() for spiesTrack calls and arguments. Prefer over manual tracking variables.
Clean up after testsUse afterEach for DOM cleanup, timer restoration, server reset. Leaking state causes flaky tests.
Avoid test.skip accumulationSkipped tests rot. Fix or delete within one sprint.

Default Tools

ToolPurposeInstall
VitestTest runner and assertion librarynpm i -D vitest
@testing-library/reactComponent rendering and queriesnpm i -D @testing-library/react
@testing-library/user-eventRealistic user interaction simulationnpm i -D @testing-library/user-event
@testing-library/jest-domExtended DOM matchers (toBeInTheDocument, etc.)npm i -D @testing-library/jest-dom
mswNetwork-level API mockingnpm i -D msw
PlaywrightE2E browser testingnpm i -D @playwright/test

When Tests Are Done

Deliver tests that meet these checks:

  • Every test has a clear name. Reading the test name alone tells you what broke.
  • No implementation details tested. Tests don't reference internal variable names, CSS classes (prefer roles), or private methods.
  • Edge cases are covered. At minimum: null input, empty collection, error path.
  • Tests run independently. Shuffle the order — they should still pass.
  • Mocks are minimal. Only mock what crosses a boundary (network, file system, time). Let everything else run for real.

Heefeg gestallte Froen

Wat mécht de KI-Skill Test Write?

Generate tests for existing code including unit, integration, and e2e tests. Uses Vitest and Testing Library by default. Use when user says "write tests", "add tests", "test this function", "test this component", "need test coverage", or wants tests written for existing code.

Firwat Test Write op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Test Write besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Test Write an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/kazdenc/builder-skills/tree/main/.claude/skills/dev/test/test-write an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Test Write benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Test Write benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Test Write domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Test Write gratis?

Jo. De Skill gëtt vum kazdenc ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇