Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

unit-tests

/unit-tests

Pisze lub przegląda testy jednostkowe przez eksportowane zachowanie, także testy regresji i kruche sprawdzenia do wymiany.

Licencja
MIT
Ostatnia zmiana repozytorium
28.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 28.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pisze lub przegląda testy jednostkowe przez eksportowane zachowanie, także testy regresji i kruche sprawdzenia do wymiany.

Argumenty

/unit-tests [file or directory to test or review]
Oryginalny opis (EN)

Write or review unit tests through exported behavior. Use for new tests, bug-fix regression tests, coverage, replacing brittle implementation checks, or a test that went red because behaviour changed on purpose.

Jak działa

  1. Worktree isolation
  2. The failure mode this exists to stop
  3. The two questions
  4. Shape
  5. Tests are scratchpad
  6. Never test
  7. Worth testing
  8. Reviewing an existing suite
Sekcje z nagłówków SKILL.md, w oryginale · 96 linii, 685 słów
Podgląd SKILL.md
---
name: unit-tests
description: "Write or review unit tests through exported behavior. Use for new tests, bug-fix regression tests, coverage, replacing brittle implementation checks, or a test that went red because behaviour changed on purpose."
argument-hint: "[file or directory to test or review]"
license: MIT
---

# Unit Tests

A unit test exercises an API. Input goes in, output gets asserted. Everything else is a fact check against the source file and should be deleted.

## Worktree isolation

Before writing or deleting tests, read and follow the [worktree isolation contract](../../references/worktree-isolation.md).
Keep mutation in a task-owned `wt` worktree with a live claim. Keep the primary checkout read only.

## The failure mode this exists to stop

Fact-check tests restate what the file already says. They pass by construction, break on harmless refactors, and prove nothing.

```ts
// all of these are fact checks, not tests
expect(Object.keys(config)).toEqual(['name', 'hooks', 'setup'])
expect(source).toContain('export function resolvePath')
expect(module.default.name).toBe('my-module')
expect(handlers).toHaveLength(3)
expect(typeof createClient).toBe('function')
```

They feel productive because the file goes green. The suite grows, review cost grows, and no bug is ever caught.

## The two questions

Before keeping any assertion:

1. **Delete it if it can fail while the code is still correct.** Renaming an internal, reordering an array, adding a config key must never turn the suite red.
2. **Delete it if it can pass while the code is broken.**

An assertion that survives both is testing behaviour. Anything else is ballast.

## Shape

Every test is three lines of intent: build an input, call an export, assert the result.

```ts
it('rejects a path outside the root', () => {
  const result = resolvePath('/srv/app', '../../etc/passwd')
  expect(result).toEqual({ _tag: 'Err', reason: 'escapes-root' })
})
```

- Call it the way a consumer calls it: through `exports`, not through a deep internal import.
- Assert on the **returned value**, the **thrown error**, or a **recorded side effect** at the boundary. Not on internal state.
- One concrete input, one concrete expectation. Table-drive the variants with `it.each`.
- Prefer a real fixture over a mock. Mocking the module under test means you are testing the mock.

## Tests are scratchpad

Cheap to write, cheap to throw away. Deleting a test is a normal outcome, not a regression.

- When behaviour intentionally changes, **delete the test and write the new one**. Do not repair old assertions until they go green; that is how a suite ossifies around an API nobody wants.
- Never write a test to raise coverage. Untested trivial code is fine.
- If a test costs more to maintain than the bug it would catch, it is negative value. Remove it.
- A test file should be deletable in one commit without anyone needing to reconstruct why it existed.

## Never test

- File contents, `dist/` output, or source text as a string
- That a symbol exists, is a function, or has N keys
- The shape of a config or options object
- Snapshots of anything except stable output a human actually reads (rendered markup, generated file a user opens, CLI output). Never snapshot an internal data structure.
- "Does not throw" as the only assertion
- Private/internal functions reached by deep import

## Worth testing

- **Pure functions**: input to output, including the boring edges (empty, zero, unicode).
- **Error paths**: bad input produces the tagged `Err` or the thrown error with the right discriminant.
- **Boundary parsers**: untrusted input becomes a precise type, or is rejected.
- **Transforms and builds**: feed a real fixture in, assert on the **parsed output value**, not the emitted text.
- **Regressions**: the failing test written before a bug fix, named for the behaviour, not the ticket.

## Reviewing an existing suite

Read the file and bucket every `expect` into fact check, behaviour, or unclear. Report the counts, list the fact checks with line numbers, and propose deletions. Do not rewrite a fact check into a behaviour test unless the underlying behaviour is genuinely worth covering; usually the right patch is a deletion.

Report in this shape:

```
resolve-path.test.ts — 14 expects: 9 fact check, 4 behaviour, 1 unclear

Delete (fact check):
  L12  expect(Object.keys(opts)).toEqual([...])   restates the options type
  L27  expect(typeof resolvePath).toBe('function') passes by construction
  L31-38  snapshot of the internal config object

Unclear:
  L44  asserts cache.size === 1 — internal state; is the caching itself a documented guarantee?

Keep: L52, L58, L63, L70 (input to output, incl. two error paths)
```

Wersje

RepozytoriumWynikLicencja
Ta strona · harlan-zw/harlan-claude-code100MIT
anomalyco/opencode100MIT
bklit/bklit-ui100MIT
thedaviddias/front-end-checklist100MIT
microsoft/vscode98MIT
percival-de-galles/waypoint-ide98MIT

Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki 71b3c5186115 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 90write-tests
    Pisze i przegląda trwałe testy, które potwierdzają rzeczywiste zachowanie, przy nowym kodzie, regresji i refaktoryzacji.
  • 86write-tests
    Pisze lub rozszerza testy dla kodu: jednostkowe, regresyjne dla błędu albo pokrycie nowej funkcji.
  • 100write-tests
    Pisze lub przegląda testy jednostkowe dla kodu w repozytorium, gdy trzeba dodać nowe testy, sprawdzić istniejące albo zwiększyć pokrycie.
  • 100write-tests
    Pisze testy jednostkowe i integracyjne dla istniejącego kodu, także w podejściu TDD, gdy brakuje testów.
  • 90write-tests
    Pisze testy zachowania produktu zamiast szczegółów implementacji i wartości konfiguracji, a także naprawia kruche testy.
  • 100unit-testing
    Pisze i aktualizuje testy jednostkowe dla nowego lub zmienionego kodu, uruchamia je z pokryciem i naprawia błędy.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.