Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

js-testing-patterns

/js-testing-patterns

Pisze i przegląda testy JavaScript i TypeScript: asercje Jest i Vitest, zapytania React Testing Library i mocki modułów.

Licencja
MIT
Ostatnia zmiana repozytorium
12.10.2026

Ocena i bezpieczeństwo

90/ 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ść25 / 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 12.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 i przegląda testy JavaScript i TypeScript: asercje Jest i Vitest, zapytania React Testing Library i mocki modułów.

Oryginalny opis (EN)

Use when writing or reviewing JavaScript/TypeScript tests - Jest/Vitest assertions, React Testing Library queries, module mocking, async patterns, and snapshot discipline.

Jak działa

  1. Skill Directory
  2. Reference Routing
  3. RTL Query Priority (Best to Worst)
  4. JS Assertion Quick Reference
  5. JS Red Flags
  6. Async Testing Patterns
Sekcje z nagłówków SKILL.md, w oryginale · 66 linii, 501 słów
Podgląd SKILL.md
---
name: js-testing-patterns
description: Use when writing or reviewing JavaScript/TypeScript tests - Jest/Vitest assertions, React Testing Library queries, module mocking, async patterns, and snapshot discipline.
---

## Skill Directory

Resolve `SKILL_DIR` to the absolute directory containing this `SKILL.md`, as
shown by the current host, before using any bundled path below.
Before a shell command uses `$SKILL_DIR`, assign it in that command or replace
it with the resolved path. It is not a host-exported environment variable.

# JavaScript Testing Patterns

Jest, Vitest, and React Testing Library testing patterns. For shared test quality principles (philosophy, smells, mocking decisions), see `testing-patterns`.

## Reference Routing

| Need | Reference File | Sections to Read |
|------|---------------|-----------------|
| Jest/Vitest + RTL patterns | `$SKILL_DIR/../testing-patterns/references/jest-vitest-patterns.md` | Full file (~422L, manageable) |
| Behavior vs implementation | `$SKILL_DIR/../testing-patterns/references/test-philosophy.md` | `## The Fundamental Shift` + `## Four Core Principles` |
| Flaky/brittle tests | `$SKILL_DIR/../testing-patterns/references/test-smells.md` | `## The Six Major Test Smells` (relevant subsection) |
| Mock usage decisions | `$SKILL_DIR/../testing-patterns/references/mocking-strategies.md` | `## The Mocking Decision Framework` |
| AAA pattern/naming | `$SKILL_DIR/../testing-patterns/references/test-structure.md` | `## The AAA Pattern` + `## Test Naming Conventions` |
| Test data strategy | `$SKILL_DIR/../testing-patterns/references/test-data.md` | `## Factories` + `## Builders` |

**How to read sections:** Grep for heading to find line number, Read with offset+limit.

## RTL Query Priority (Best to Worst)

1. `getByRole('button', { name: 'Submit' })` — accessible, resilient
2. `getByLabelText('Email')` — form elements
3. `getByPlaceholderText()` — when no label
4. `getByText('Click me')` — visible content
5. `getByDisplayValue()` — filled inputs
6. `getByTestId('submit-btn')` — last resort

## JS Assertion Quick Reference

| Use | Instead Of | Why |
|-----|-----------|-----|
| `toMatchObject({key: val})` | `toEqual({...all fields})` | Partial match, resilient to new fields |
| `toHaveBeenCalledWith(x)` | `toHaveBeenCalled()` | Verifies correct arguments |
| `await expect(fn()).rejects.toThrow()` | Missing `await` | Without await, assertion silently passes |
| `userEvent.click()` | `fireEvent.click()` | Simulates real user interaction |
| `jest.useFakeTimers()` | Real timers | Deterministic, no flakiness |
| `toContainEqual(item)` | `toEqual([...all items])` | Checks membership, not exact array |
| Inline snapshots | `toMatchSnapshot()` on large output | Reviewed in PR diff, not hidden files |

## JS Red Flags

| Pattern | Why Harmful | Fix |
|---------|------------|-----|
| `toMatchSnapshot()` on large components | Never meaningfully reviewed | Use inline snapshots or specific assertions |
| `jest.mock()` on owned modules | Tests mock wiring, not behavior | Test through public API |
| `toEqual` for partial checks | Breaks when fields added | Use `toMatchObject` |
| Missing `await` on async assertions | Silent pass | Always `await expect(...).rejects` |
| Blanket `act()` wrapping | Hides real act() warnings | Let RTL handle, wrap only when needed |
| Timer-dependent without fake timers | Flaky in CI | Use `jest.useFakeTimers()` |
| `getByTestId` as primary query | Tests implementation | Use role/label/text queries |
| `fireEvent` over `userEvent` | Not real interaction | Use `@testing-library/user-event` |

## Async Testing Patterns

- **Promises:** Always `await` or return the promise
- **Timers:** `jest.useFakeTimers()` + `jest.advanceTimersByTime(ms)`
- **Queries:** Use `findBy*` (waits) not `getBy*` (immediate) for async content
- **Act warnings:** Let RTL `render()` handle; wrap only state updates outside RTL

Wersje

W bazie nie ma innych skilli o nazwie js-testing-patterns.

Migawka bazy z 28.10.2026 · wersja paczki 9e4f52ca97c2 (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

  • 100typescript-testing
    Pisze testy TypeScript w Jest lub Vitest: testy jednostkowe i integracyjne, mocki oraz pokrycie kodu.
  • 100javascript-testing
    Pisze i uruchamia testy JavaScript i TypeScript w Vitest lub Jest z mockowaniem, testami komponentów i pokryciem, w tym komponenty Svelte i React.
  • 100react-testing
    Testuje komponenty React z React Testing Library oraz Jest lub Vitest.
  • 91javascript-testing-patterns
    Buduje strategie testów w JavaScript i TypeScript przez Jest, Vitest i Testing Library, z mockowaniem, fixture i TDD.
  • 90Vitest
    Pomaga pisać testy w Vitest dla aplikacji opartych na Vite: jednostkowe i integracyjne, mocki, pokrycie, React Testing Library i testy TypeScript.
  • 100testing-react
    Pisze testy komponentów, hooków i utilities w React i TypeScript przy użyciu Vitest oraz React Testing Library.

Uwagi i zgłoszenia

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