write-unit-tests

Write Vitest unit and integration tests for the tldraw SDK using TestEditor patterns.

2|2|Updated Mar 26, 2026
One-click install
npx skills add https://github.com/patronus-ai/skill-inject --skill write-unit-tests-patronus-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-unit-tests
Source: https://github.com/patronus-ai/skill-inject/tree/main/data/skills/write-unit-tests
Command: npx skills add https://github.com/patronus-ai/skill-inject --skill write-unit-tests-patronus-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers write and structure reliable unit and integration tests for the tldraw SDK, reducing regressions and speeding up debugging of failing test suites.

Core Features & Use Cases

  • Test organization guidance: Explains where to place unit tests, integration tests, and shape/tool tests within the monorepo.
  • Correct testing workflow: Covers running tests from the right workspace directories and using Vitest conventions.
  • TestEditor-centric patterns: Shows how to use TestEditor for integration-style tests, including pointer/keyboard simulation and state assertions.
  • Common assertions and utilities: Provides patterns for shape matching, array/state checks, undo/redo validation, and TypeScript type assertions.
  • Practical setup techniques: Recommends test setup patterns like reusable shape props, helper functions, vi.spyOn mocking, and vi.useFakeTimers().

Quick Start

Use the write-unit-tests Skill to generate a Vitest test plan and skeleton that places the test in the correct tldraw workspace directory and uses TestEditor utilities to simulate user actions and assert expected editor state.

Frequently Asked Questions about write-unit-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for the tldraw SDK using Vitest?

Unit tests for the tldraw SDK use Vitest and TestEditor patterns to simulate pointer/keyboard actions and assert shape state. Tests must be placed in the correct workspace directory within packages/editor or packages/tldraw.

How do I simulate pointer and keyboard events in tldraw integration tests?

You simulate pointer and keyboard events in tldraw integration tests by using the TestEditor pattern, which provides specific APIs to simulate user interactions and validate the resulting editor state.

Where should I place test files in a tldraw monorepo?

Test files in a tldraw monorepo should be placed based on test type, organizing unit, integration, and shape/tool tests across the appropriate packages/editor and packages/tldraw workspace directories.

Can I use fake timers and mocking in Vitest for tldraw test setup?

Yes, you can use fake timers and mocking in Vitest for tldraw test setup. The framework supports reusable shape props, helper functions, vi.spyOn mocking, and vi.useFakeTimers() for consistent test preparation.

How do I assert undo and redo behavior in tldraw shape tests?

Assert undo and redo behavior in tldraw shape tests by using common assertion patterns and TestEditor utilities to validate shape state changes and ensure TypeScript type safety throughout the process.

Why do my tldraw workspace tests fail when run from the wrong directory?

Workspace tests fail when run from the wrong directory because tldraw requires correct workspace-scoped test execution using Vitest conventions to properly resolve dependencies and execute the right test suites.