writing-tests
БесплатноБез исполняемых скриптовНе проверенHow to write tests in the Portable Text Editor monorepo. Use whenever writing or editing tests in PTE packages. Covers test placement, harnesses…
от portabletext★ 290 звёзд на GitHubОб этом скилле
Writing PTE tests
Test placement
Before writing any test, find its existing home. Always search for an established suite covering the domain (ls tests/ | grep -i <topic>, rg -l <mechanism> tests/) and read its scenario list before creating a file. The canonical suites are broad (behavior-api.test.tsx carries 30+ Behavior contract scenarios); a contract pin belongs next to its siblings, where reviewers and future failures will look for it. A new file is the exception, for a genuinely new domain, not the default. Also check whether the contract is already pinned in a different form before adding it at all.
The file extension is the discriminator, never a .browser suffix:
*.test.tsxruns in the browser project (playwright: chromium, firefox, webkit)*.test.tsruns in the unit project (node)*.test-d.tsis type-level, usingexpectTypeOffrom vitestgherkin-tests/*.feature+ racejar for behavior specs (Feature({featureText, stepDefinitions, parameterTypes}))
When scaffolding a new package, mirror plugin-paste-link's vitest config: a browser project including src/**/*.test.tsx and a unit project including src/**/*.test.ts.
Choosing the form
- When textspec can state the case (the document and selection before, the action, the document and selection after), write it as a Gherkin scenario using the existing steps. Editor scenarios go in
gherkin-spec/, plugin scenarios in a.featurenext to the plugin source. - When textspec can't state it (emitted events or patches, paths, or anything else outside the notation), write a plain test with every value written out, even when that makes the file long. Don't bend a scenario to fit by adding steps that take or check JSON.
- No
.eachwhose rows are built by helpers. A table of fixture builders, path builders and wrappers makes the reader assemble each case in their head. Write each case out as its own test.
Harnesses
- Editor integration tests:
createTestEditorfrom@portabletext/editor/test/vitest(inside the editor package:../src/test/vitest). Returns{editor, locator}. Plugins and probes go in aschildren, but note they mount as siblings afterPortableTextEditable; a provider that must wrap the editable needs a hand-rolled render with a comment explaining why. - Selector/pure-function tests:
createTestSnapshot(in the editor package:test-utils/create-test-snapshot; in plugins: duplicate it locally on public types, it is ~30 lines). - Keys: always
createTestKeyGeneratorfrom@portabletext/test. It is deterministic (k0,k1, ...), which is what makes full-literal assertions possible. Generated keys may be asserted literally.
Triggers
- Real user interaction via
userEvent(userEvent.type(locator, 'foo')). Typing with no caret set lands at the block start. - Everything else via
editor.send({type: ...})with full payloads. This includes native-shaped events:drag.dragover,drag.dropetc. accept completeposition/dragOrigin/originEventobjects, so no DOM event simulation is needed to test a behavior. - The exception is a test of the editable's own handling of a native event that
userEventcannot produce, such as abeforeinputinput type keyboard input never fires. Set a real DOM selection and dispatch the real event on the editable (new InputEvent('beforeinput', {inputType, bubbles: true, cancelable: true})). - Wait for content to render before focusing or selecting in it. A
focusorselectsent straight after inserting blocks can land before the DOM exists and fail silently. - Async settling via
vi.waitForaround the assertion that proves the trigger landed. Debounced channels (the mutation batcher) need their ownvi.waitFor; comparing them synchronously after another assertion passes is a race. - Every DOM query goes inside the retried callback. A
querySelectorrun once beforevi.waitForis never re-run, so the wait checks the same stale element ornullon every retry. - A lone locator assertion is awaited directly:
await expect.element(locator).toBeVisible(), not wrapped invi.waitFor.expect.elementalready retries until its own timeout, and the wrapper cuts that tovi.waitFor's 1s default. Pass a longer timeout toexpect.elementitself (expect.element(locator, {timeout: 10_000})). - Never sleep (
setTimeout, arbitrary delays), even for negative asserts. To prove "nothing was emitted", create a deterministic flush point: perform a local edit through the same ordered channel and assert the full emission list contains exactly that edit's patches, a would-be echo would have to surface no later than the edit's own emission. This also upgrades the negative assert to a full-value pin. The only exception is a wait with no observable signal to anchor on, such as a real IME sequence driven through CDP, and it carries a comment naming the missing signal. - Simulated races are event-driven, never clock-driven. To reco
Установить writing-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл writing-tests?
How to write tests in the Portable Text Editor monorepo. Use whenever writing or editing tests in PTE packages. Covers test placement, harnesses, deterministic fixtures, and the house assertion style (no indirection, full values with toEqual).
Как установить скилл writing-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл writing-tests запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic