Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

test-assertions

/test-assertions

Pisze asercje jako pełne, ścisłe porównania równości i przepisuje istniejące testy do tego samego standardu.

Licencja
Apache-2.0
Ostatnia zmiana repozytorium
26.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 26.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

Co robi i kiedy

Pisze asercje jako pełne, ścisłe porównania równości i przepisuje istniejące testy do tego samego standardu.

Oryginalny opis (EN)

Write test assertions as complete, strict deep-equality checks, and rewrite existing tests to the same standard. Use when writing new tests, adding assertions, reviewing test quality, strengthening weak tests, or replacing fragmented assertions in a file, directory, diff, or repository.

Jak działa

  1. Select the scope
  2. Prefer the strongest assertion
  3. Discover expected values from the test
  4. Assert the whole value at once
  5. Control dynamic properties
  6. Verify
Sekcje z nagłówków SKILL.md, w oryginale · 156 linii, 796 słów
Podgląd SKILL.md
---
name: test-assertions
description: Write test assertions as complete, strict deep-equality checks, and rewrite existing tests to the same standard. Use when writing new tests, adding assertions, reviewing test quality, strengthening weak tests, or replacing fragmented assertions in a file, directory, diff, or repository.
---

# Strict Test Assertions

Capture a value's complete structure in one strict deep-equality check instead of a cluster of narrow checks. When rewriting existing tests, rethink each test as a whole rather than tweaking individual lines, and collapse weak assertions about the same value into one strict check against the complete expected value.

## Select the scope

- Use the file or directory named by the user when provided.
- Otherwise, use test files in staged and unstaged changes when the working tree contains changes.
- Otherwise, use all test files in the repository.

Do not change snapshot assertions (`toMatchSnapshot`) unless the user explicitly includes them.

## Prefer the strongest assertion

Use the strictest deep-equality matcher the framework offers for structured values (in Jest, `toStrictEqual`). Ranked from worst to best, in Jest and Chai terms; only the last is good enough:

- `toBeTruthy`, `toBeDefined`, `not.toBeNull`: barely checks anything
- `toHaveProperty('key')`: only checks existence, not value
- `toContain`, `toMatch`: substring/regex match hides the full value
- `toHaveLength(n)`: only checks count, not contents
- `toMatchObject`, `objectContaining`, `arrayContaining`: allows extra properties to sneak in
- `toEqual`, `to.deep.equal`: close, but ignores class mismatches and undefined vs missing
- **`toStrictEqual`**: the only acceptable assertion for objects and arrays

Migrate existing `toEqual` and `to.deep.equal` assertions to `toStrictEqual` too. Use exact equality for primitives (in Jest, `toBe` is fine for strings, numbers, booleans, null). Tighten calls and exceptions to their exact observable contract: the exact arguments, error type, and message.

- `toThrow()` or `toThrow(/partial/)` → `toThrow(new SpecificError("exact message"))`
- `toHaveBeenCalled()` → `toHaveBeenCalledWith("exact", "args")`

## Discover expected values from the test

Do not infer an expected value from implementation code. When writing a new assertion or replacing a weak one, start with a deliberately incomplete strict assertion, run the narrowest relevant test, and use the failure output to capture the actual value. Then review that value as the intended contract and rerun the test to confirm it passes.

```ts
// Before: three assertions that barely check anything
const result = await Children.run(['--json', '--projects-dir', '/tmp/fake-projects']);
expect(result).toHaveProperty('projects');
expect(result).toHaveProperty('summary');
expect(result.summary.total).toBe(2);

// First: replace with a placeholder; do NOT guess the expected value
expect(result).toStrictEqual({});

// Then: run the test, read the actual value from the error output, paste it in
expect(result).toStrictEqual({
	projects: [
		{name: 'project-a', path: '/tmp/fake-projects/project-a'},
		{name: 'project-b', path: '/tmp/fake-projects/project-b'},
	],
	summary: {total: 2, active: 2},
});
```

If the observed value reveals a bug or an unclear contract, stop and ask the user instead of blessing it as expected behavior.

## Assert the whole value at once

Even when each assertion is already strict, splitting them across properties loses the structural picture and makes failures harder to diagnose:

```ts
// Before: correct but fragmented; each line is fine on its own
const result = processOrder(input);
expect(result.id).toBe('order-42');
expect(result.status).toBe('confirmed');
expect(result.total).toBe(119.99);
expect(result.currency).toBe('USD');
expect(result.items).toStrictEqual([
	{sku: 'A1', qty: 2},
	{sku: 'B3', qty: 1},
]);
expect(result.shipping.method).toBe('express');
expect(result.shipping.estimatedDays).toBe(3);
expect(result.tags).toStrictEqual([]);

// After: one assertion captures the complete value
expect(result).toStrictEqual({
	id: 'order-42',
	status: 'confirmed',
	total: 119.99,
	currency: 'USD',
	items: [
		{sku: 'A1', qty: 2},
		{sku: 'B3', qty: 1},
	],
	shipping: {method: 'express', estimatedDays: 3},
	tags: [],
});
```

### Redundant guards

Don't assert length, size, or existence right before asserting the full value; the content assertion already implies it:

```ts
// BAD: toHaveLength is redundant
expect(result).toHaveLength(2);
expect(result[0].name).toBe('a');
expect(result[1].name).toBe('b');

// GOOD: one assertion covers length AND contents
expect(result.map((r) => r.name)).toStrictEqual(['a', 'b']);
```

Same for `toBeDefined()` / `not.toBeNull()` before property access: if the value were nullish, the next line would throw anyway.

### Native collection types

Assert Sets and Maps directly rather than converting them to arrays:

```ts
// BAD: pointless conversion
expect([...result]).toStrictEqual(['a', 'b']);

// GOOD: assert the actual type
expect(result).toStrictEqual(new Set(['a', 'b']));
```

## Control dynamic properties

Prefer deterministic test data for timestamps, temp paths, and UUIDs: freeze time, inject identifiers, use fixed test paths. When a value comes from outside the test's control, don't fall back to weak assertions. Assert the dynamic properties individually, strip them, and assert strict equality on the rest:

```ts
const result = await createReport();

// Assert dynamic properties individually
expect(result.createdAt).toBeInstanceOf(Date);
expect(result.tempDir).toMatch(/^\/tmp\//);

// Strip them, then assert everything else strictly
const {createdAt, tempDir, ...rest} = result;
expect(rest).toStrictEqual({
	title: 'Q1 Report',
	status: 'complete',
	items: [{id: 1, name: 'revenue'}],
});
```

Never put `instanceof` or type checks inside assertion objects. A failure then shows `false !== true` instead of the actual value.

```ts
// BAD: hides the actual value
expect({createdAt: result.createdAt instanceof Date}).toStrictEqual({
	createdAt: true,
});

// GOOD: shows the actual value on failure
expect(result.createdAt).toStrictEqual(new Date(1_704_067_200 * 1000));
```

When the full expected value would be enormous (more than about 50 lines), extract it into a clearly named `const` at the top of the test or a fixture file.

## Verify

Run the narrowest affected tests while discovering values, then run the repository's applicable test and precommit checks. Leave no placeholder assertions behind.

Wersje

W bazie nie ma innych skilli o nazwie test-assertions.

Migawka bazy z 13.11.2026 · wersja paczki 2d50756e07b7 (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

  • 95write-tests
    Pisze testy jednostkowe w Vitest i testy E2E w Playwright według praktyk doświadczonych inżynierów testów, w tym pokrycie, przypadki brzegowe i brakujące asercje.
  • 100write-tests
    Pisze lub przegląda testy jednostkowe dla kodu w repozytorium, gdy trzeba dodać nowe testy, sprawdzić istniejące albo zwiększyć pokrycie.
  • 95test-quality
    Pisze testy w JUnit 5 z asercjami AssertJ, dodaje brakujące przypadki i poprawia pokrycie kodu Javy.
  • 95move-unit-testing
    Pisze testy jednostkowe dla modułów Move na Sui: nazwy funkcji testowych, asercje, atrybuty testów i sprzątanie.
  • 100test-quality-analysis
    Analizuje jakość kodu testów, wykrywa testy wyłącznie podbijające pokrycie, test smells i asercje o niskiej wartości, ocenia testy w skali 1-5 i tworzy raport priorytetów poprawek.
  • 100writing-tests
    Analizuje istniejący kod i pisze testy jednostkowe i integracyjne: wykrywa framework testowy, znajduje nieprzetestowane ścieżki i generuje mocki, przypadki brzegowe i asercje.

Uwagi i zgłoszenia

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