用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/li-kai/skills --skill typescript-tests命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | typescript-tests |
| description | TypeScript testing with test.each patterns and async handling. Use when writing or reviewing TypeScript tests. |
| paths | ["**/*.test.ts","**/*.test.tsx"] |
See common testing practices for general philosophy.
Run tests with pnpm test.
test.each([
["user@gmail.com", true],
["invalid.com", false],
])("isValidEmail(%s) returns %s", (email, expected) => {
expect(isValidEmail(email)).toBe(expected)
})
test.each([
{ name: "empty array", input: [], expected: { sum: 0, avg: 0 } },
{ name: "single number", input: [5], expected: { sum: 5, avg: 5 } },
])("calculateStats($name)", ({ input, expected }) => {
expect(calculateStats(input)).toEqual(expected)
})
When cases use types with index signatures (e.g., Record<string, T>) or unions
like boolean | SchemaObject, TypeScript infers a union across array elements
that adds prop?: undefined, breaking Record assignability.
Fix with test.each<T>([...] as const satisfies T[]):
type Case = { name: string; schema: JsonSchema; expected: JsonSchema }
test.each<Case>([
{
name: "string",
schema: { type: "string" },
expected: { type: "string" },
},
{
name: "ref",
schema: { $ref: "#/$defs/Foo" },
expected: { type: "number" },
},
] as const satisfies Case[])("expand($name)", ({ schema, expected }) => {
expect(expandSchema(schema)).toEqual(expected)
})
test.each<T> types the callback parameter, preventing union wideningas const satisfies T[] narrows literals, catching typos like
type: "strig" against a string literal unionWithout strict types, plain test.each([...]) is fine.
Use test.for instead of test.each when you need TestContext (e.g.,
concurrent snapshot tests). Otherwise the two are equivalent.
Keep tests flat. Use descriptive test names instead of nested describe blocks.
Only use describe() when you need shared beforeEach/afterEach, one level
max.
test.each([{ url: "/users/1", expected: { id: 1 } }])(
"fetchUser($url) returns user",
async ({ url, expected }) => {
expect(await fetchUser(url)).toEqual(expected)
},
)
test.each([
{ input: null, error: "Cannot be null" },
{ input: -1, error: "Must be positive" },
])("validate($input) throws $error", ({ input, error }) => {
expect(() => validate(input)).toThrow(error)
})