Toolverse
All skills

write-unit-tests

by tldraw

Writing unit and integration tests for the tldraw SDK. Use when creating new tests, adding test coverage, or fixing failing tests in packages/editor or packages/tldraw. Covers Vitest patterns, TestEditor usage, and test file organization.

Installation

Pick a client and clone the repository into its skills directory.

Installation

Quick info

Author
tldraw
Category
Testing
Views
42

About this skill

Writing unit and integration tests for the tldraw SDK. Use when creating new tests, adding test coverage, or fixing failing tests in packages/editor or packages/tldraw. Covers Vitest patterns, TestEditor usage, and test file organization.

How to use

  1. Przejdź do odpowiedniego pakietu: dla testów jednostkowych i geometrii przejdź do packages/editor, dla testów integracyjnych z domyślnymi kształtami i narzędziami przejdź do packages/tldraw.

  2. Umieść plik testowy w odpowiedniej lokalizacji: testy jednostkowe umieszczaj obok pliku źródłowego z rozszerzeniem .test.ts (np. Vec.ts i Vec.test.ts w tym samym katalogu), testy integracyjne umieszczaj w katalogu src/test/ (np. src/test/SelectTool.test.ts).

  3. Dla testów integracyjnych zaimportuj TestEditor zamiast zwykłego Editor, ponieważ TestEditor zawiera domyślne kształty i narzędzia. Zainicjuj TestEditor w bloku beforeEach i wyczyść go w afterEach za pomocą dispose().

  4. Dla testów konfiguracji edytora lub niestandardowych ustawień użyj surowego Editor z createTLStore i przekaż swoje niestandardowe kształty, narzędzia i bindowania.

  5. Uruchom testy z poziomu katalogu pakietu poleceniem yarn test run, opcjonalnie z flagą --grep aby uruchomić konkretny test (np. yarn test run --grep "SelectTool").

Related skills