Toolverse
All skills

javascript-testing-patterns

by wshobson

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

Quick info

Author
wshobson
Category
Testing
Views
23

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

  1. 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.

  2. Skonfiguruj framework testowy, wybierając między Jest (pełnofunkcyjny, uniwersalny) a Vitest (szybki, natywny dla Vite). Dla Jest utwórz plik jest.config.ts z presetem ts-jest, zdefiniuj katalogi testów w testMatch oraz ustaw progi pokrycia kodu (np. 80% dla branches, functions, lines i statements).

  3. Dla Vitest utwórz vitest.config.ts z konfiguracją środowiska testowego, dostawcą coverage (v8) i formatami raportów (text, json, html). Dodaj plik setupu testów, jeśli potrzebujesz globalnych konfiguracji.

  4. 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.

  5. 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.

  6. 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.

Related skills