testing
БесплатноЗапускает вложенные скриптыНе проверенProvides expertise on how to write effective unit tests (runtime and type tests), make testing decisions, and incorporate TDD into development workflows
Об этом скилле
Testing Skill
Overview
This skill provides comprehensive guidance on testing in TypeScript projects, with a focus on the dual nature of testing: runtime behavior and type correctness. It covers when to use each type of test, how to structure tests effectively, and how to integrate testing into development workflows using Test-Driven Development (TDD).
Types of Testing
1. Runtime Tests
Runtime tests verify the actual behavior of code during execution.
When to use:
- Testing function outputs with various inputs
- Verifying error handling and edge cases
- Checking side effects (file I/O, API calls, state mutations)
- Validating business logic and algorithms
- Testing class instance behavior and methods
Tools:
- Test runner: Vitest
- Commands:
pnpm test- runs all runtime testspnpm test GLOB- runs tests matching the glob pattern
Example structure:
import { describe, it, expect } from "vitest";
import { prettyPath } from "~/utils";
describe("prettyPath()", () => {
it("should format a path with directory and filename", () => {
const result = prettyPath("/path/to/file.ts");
expect(result).toBe("/path/to/file.ts"); // Expected formatting
});
it("should handle edge case: empty string", () => {
const result = prettyPath("");
expect(result).toBe("");
});
it("should handle edge case: root path", () => {
const result = prettyPath("/");
expect(result).toBe("/");
});
});
2. Type Tests
Type tests verify the type correctness of TypeScript code at design time.
When to use:
- Testing type utility functions (always)
- Verifying generic type constraints work as expected
- Ensuring conditional types resolve correctly
- Testing that complex inferred types are accurate
- Validating discriminated unions and type narrowing
- Checking that function signatures accept/reject correct types
Tools:
- Commands:
pnpm test:types- runs all type testspnpm test:types GLOB- runs type tests matching the glob pattern
Type Test Structure
This section will show you, layer by layer, how to compose and build good type tests.
cases block
All type tests in a given it test block (defined by Vitest) will have a type called cases defined as an array of type tests.
type cases = [
// ... type tests go here
]
Note: our linting rules allow for the name
casesto be defined without being used; this is intentional and a good thing.
Expect<...> wrapper
Every type test will be wrapped by an Expect type utility.
type cases = [
Expect<...>,
Expect<...>,
// ...
]
Available Type Test Assertions
The inferred-types library provides a number of useful assertion utilities you can use to create your tests:
AssertTrue<T>****- tests whether the tested type
Tis the typetrue
- tests whether the tested type
AssertFalse<T>- tests whether the tested type
Tis the typefalse
- tests whether the tested type
AssertEqual<T,E>- tests that the tested type
Tequals the expected typeE
- tests that the tested type
AssertExtends<T,E>- tests that the tested type
Textends the expected typeE
- tests that the tested type
AssertSameValues<T,E>- tests that the tested type
Tis an array type and every element ofEandTare the same but the order in which they arrive does not matter
- tests that the tested type
AssertContains<T,E>- when the tested type
Tis astring:- this utility will pass when
Eis also astringand represents a sub-string of the sting literalT
- this utility will pass when
- when the tested type
Tis an array then:- this utility
- when the tested type
In all cases you put the test assertion inside of the Expect utility:
type cases [
Expect<AssertTrue<T>>,
Expect<AssertExtends<T, string>>,
// ...
]
Example 1
In our example we'll just test a built-in type utility of Typescript's named Capitalize<T>.
- this utility simply capitalizes the first letter in a string literal
import type { Expect, Equal } from "inferred-types/types";
describe("Example 1", () => {
it("string literals", () => {
type Lowercase = Capitalize<"foo">;
type AlreadyCapitalized = Capitalize<"Foo">;
type cases = [
Expect<AssertEqual<Lowercase, "Foo">>,
Expect<AssertEqual<AlreadyCapitalized, "Foo">>,
]
});
it("wide string", () => {
type Wide = Capitalize<string>;
type cases = [
Expect<AssertEqual<Wide, string>>
]
})
it("only first letter capitalized", () => {
type SpaceThenLetter = Capitalize<" foo">;
type TabThenLetter = Capitalize<"\tfoo">;
type cases = [
Expect<AssertEqual<SpaceThenLetter, " foo">>,
Expect<AssertEqual<TabThenLetter, "\tfoo">>,
]
})
});
IMPORTANT: in the example above we were testing a type util
Установить testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл testing?
Provides expertise on how to write effective unit tests (runtime and type tests), make testing decisions, and incorporate TDD into development workflows
Как установить скилл testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл testing запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
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