javascript-testing-patterns
Implement comprehensive testing strategies using Jest, Vitest, and Testing Library for unit tests, integration tests, and end-to-end testing with mocking, fixtures, and test-driven development. Use when writing JavaScript/TypeScript tests, setting up test infrastructure, or
Installation
Pick a client and clone the repository into its skills directory.
Installation
About this skill
Implement comprehensive testing strategies using Jest, Vitest, and Testing Library for unit tests, integration tests, and end-to-end testing with mocking, fixtures, and test-driven development. Use when writing JavaScript/TypeScript tests, setting up test infrastructure, or implementing TDD/BDD workflows.
How to use
Zainstaluj umiejętność w swoim projekcie JavaScript/TypeScript jako plugin agenta. Upewnij się, że masz zainstalowane niezbędne zależności: Jest lub Vitest oraz Testing Library dla testów komponentów.
Skonfiguruj framework testowy, wybierając między Jest (pełnofunkcyjny, uniwersalny) a Vitest (szybki, natywny dla Vite). Dla Jest utwórz plik
jest.config.tsz presetemts-jest, zdefiniuj katalogi testów wtestMatchoraz ustaw progi pokrycia kodu (np. 80% dla branches, functions, lines i statements).Dla Vitest utwórz
vitest.config.tsz konfiguracją środowiska testowego, dostawcą coverage (v8) i formatami raportów (text, json, html). Dodaj plik setupu testów, jeśli potrzebujesz globalnych konfiguracji.Napisz pierwsze testy jednostkowe dla funkcji i klas, używając describe() i it() do organizacji testów. Umiejętność dostarcza wzorce mockowania zależności zewnętrznych oraz konfiguracji fixture'ów do przygotowania danych testowych.
Dla testów integracyjnych i end-to-end skonfiguruj mockowanie API i usług. Wykorzystaj Testing Library do testowania komponentów frontend'owych w sposób zbliżony do rzeczywistego użycia aplikacji.
Zintegruj testy z pipeline'em CI/CD, uruchamiając je automatycznie przy każdym commit'cie. Umiejętność wspiera implementację test-driven development (TDD) i behavior-driven development (BDD) workflow'ów.