Skip to main content
skill CX Codex

write-unit-tests — Claude Code skill for tldraw SDK tests

A skill that guides writing unit and integration tests in the tldraw repo: where test files belong, how to drive TestEditor, and which Vitest traps to avoid.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add tldraw/tldraw --skill write-unit-tests -a claude-code
Open on GitHub

What write-unit-tests does

This skill covers test authoring in the tldraw monorepo with Vitest. Tests run from workspace directories rather than the repository root. Core primitives, geometry and managers belong in packages/editor; anything that needs default shapes or tools goes in packages/tldraw.

It lays out file placement, points at existing suites to copy from, and explains the parts you won't learn by reading a neighboring test. Wheel and pinch events are batched, so a bare editor.dispatch() does nothing until you flush with editor.emit('tick', 16). Floating-point geometry comparisons need toCloselyMatchObject instead of toMatchObject, or rounding noise breaks the assertion. Animated code requires stubbing requestAnimationFrame at module scope, since vi.useFakeTimers() doesn't drive it.

The two TestEditor classes are package-specific and can't be swapped: the one in packages/editor ships without default shapes or tools. Import from the package under test. Every suite needs editor?.dispose() in afterEach, because otherwise subscriptions and timers leak into later tests in the same file. Spies on the editor must be restored with mockRestore(), and global state has to come back in finally or afterEach.

What it helps with

  • write a first test for a new tldraw component
  • decide which workspace a test belongs in
  • fix a failing geometry assertion caused by rounding noise
  • get animation tests working with requestAnimationFrame
  • stop timer leaks between tests in one file

Example prompts for the agent

  • Write a unit test for Vec.ts next to the file
  • Add an integration test for SelectTool in packages/tldraw/src/test/
  • Fix the failing test in ArrowShapeUtil.test.ts

How to install write-unit-tests

1Skills CLI (Vercel)

npx skills add tldraw/tldraw --skill write-unit-tests -a claude-code

2Manually: put the files in place

~/.claude/skills/write-unit-tests/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/write-unit-tests/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about write-unit-tests

How do I install write-unit-tests in Claude Code?

Run npx skills add tldraw/tldraw --skill write-unit-tests -a claude-code. The skill lands at ~/.claude/skills/write-unit-tests/SKILL.md.

What does write-unit-tests do?

It explains how to write Vitest unit and integration tests in the tldraw repository: file placement, TestEditor usage, and the gotchas around events, animations and mocks.

Why doesn't a wheel event apply after dispatch?

Wheel and pinch events are batched. Call editor.emit('tick', 16) after editor.dispatch(wheelEvent) so the event actually lands.

Similar skills

All skills for Testing and QA →

From the same set10

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor