Frontend Typescript Testing logo

Frontend Typescript Testing

Community
shinpr
frontend-typescript-testing

使用仓库已配置的 React 测试与浏览器测试工具(包括 RTL、MSW、Vitest,以及存在时的 Playwright)设计前端测试。适用于新增或评审组件测试、加载/错误状态测试、集成测试或前端 E2E 测试时。

Overview

Publishershinpr
Repositoryai-coding-project-boilerplate
Skill namefrontend-typescript-testing
Stars
234
Forks
28
Bundled files
1
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by shinpr on GitHub. Read the source before you install it.

Installation

Install the Frontend Typescript Testing AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/shinpr/ai-coding-project-boilerplate/tree/main/.claude/skills-zh-CN/frontend-typescript-testing
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/shinpr/ai-coding-project-boilerplate.git /tmp/ai-coding-project-boilerplate
mkdir -p .claude/skills
cp -r /tmp/ai-coding-project-boilerplate/.claude/skills-zh-CN/frontend-typescript-testing .claude/skills/frontend-typescript-testing
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Frontend Typescript Testing in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Frontend Typescript Testing on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Frontend Typescript Testing is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

TypeScript 测试规则(前端)

前置条件检测

在选择框架或命令之前,先检查 package.json、锁文件、测试配置以及现有测试的 import。仅在依赖/配置确实存在时才应用 Vitest、React Testing Library、MSW 或 Playwright 的规则。若仓库配置了不同的等效工具,则使用该工具。若无法确定可运行的测试工具,应报告已检查的路径以及缺失的框架或命令,而不是凭空指定。

参考资料

测试类型参考使用场景
单元测试 / 集成测试本文档使用 RTL + Vitest + MSW 实现 React 组件测试
E2Ereferences/e2e.md使用 Playwright 实现浏览器级 E2E 测试

测试框架

  • Vitest:当仓库配置或现有测试选用 Vitest 时使用
  • React Testing Library:用于组件测试
  • MSW (Mock Service Worker):用于 API 模拟
  • 测试导入:import { describe, it, expect, beforeEach, vi } from 'vitest'
  • 组件测试导入:import { render, screen } from '@testing-library/react'
  • 用户交互:import userEvent from '@testing-library/user-event'
  • Mock 创建:使用 vi.mock()

基本测试策略

质量要求

  • 回归防护:在关键路径和高复用组件上,断言指定的验收结果、公开分支或失败状态
  • 独立性:每个测试都能独立运行,不依赖其他测试
  • 可复现性:控制时间、随机性、环境变量、网络响应和浏览器状态,使相同的输入产生相同的可观测结果
  • 可读性:每个测试只描述一个用户可见的行为,分离 setup/action/assertion,并将 fixture 限制为该行为实际用到的值

应将测试严谨性集中于何处

对于跨功能复用的共享组件、自定义 hook 和工具函数,应覆盖其公开分支、错误状态和边界契约,因为它们的回归影响范围更大。当行为依赖于多个已渲染单元时,通过集成测试/E2E 测试来验证页面级组合。

测试类型与范围

  1. 单元测试(React Testing Library)

    • 验证单个组件或函数的行为
    • Mock 所有外部依赖
    • 关注用户可观测的行为
  2. 集成测试(React Testing Library + MSW)

    • 验证多个组件之间的协作
    • 使用 MSW (Mock Service Worker) 模拟 API
    • 不进行实际的数据库连接(数据库由后端管理)
    • 验证实现主要验收标准或涉及多个已渲染组件协作的流程
  3. 跨功能验证

    • 当新功能触及共享的集成点时,若现有功能失效会破坏主要用户流程或契约,或降低次要可观测行为,则现有功能的连续性成为一项证明义务。在能够暴露其失效的成本最低的边界上加以证明
    • 验证模式:现有功能运行 -> 启用新功能 -> 验证现有功能的连续性
    • 成功标准:保持源验收标准所指定的显示内容与交互行为;仅在项目配置或需求定义了阈值及其度量方法时,才应用渲染耗时阈值
    • 设计为可在 CI/CD 流水线中自动执行

测试实现规范

目录结构与命名

  • 将组件的测试与该组件放在同一目录下,使实现与测试同步移动
  • 测试文件:{ComponentName}.test.tsx
  • 集成测试文件:{FeatureName}.integration.test.tsx
  • 测试套件:以描述目标组件或功能的名称命名
  • 测试用例:以描述从用户视角出发的预期行为命名

测试代码质量规则

保持每个已提交的测试处于有效状态。当测试保护的是当前行为时应修复它。在以下情况下可以删除测试:其对应行为已不再被要求,且源需求或实现契约确认该行为可移除;或者保留的另一个测试能够检测出被删除测试所检测的全部回归。

Mock 类型安全强制要求

使用 satisfies 将 MSW handler 的响应体约束为其所代表的领域类型,使偏离契约的 fixture 在编译期失败,而不是让测试针对应用实际不会收到的数据形状“通过”。

将组件或依赖的 mock 类型限定为被测对象实际使用的部分——例如 Pick<Props, 'usedProp'>、Pick<Router, 'push'>——而不是完整接口,并用 satisfies 约束该字面量,使多余或命名错误的成员在编译期失败。

测试设计模式

测试用户可见的结果,而不是实现细节。按用户感知的 role 和可访问名称查询(getByRole/getByLabelText/getByText),而不是 getByTestId 或 container.querySelector。通过 userEvent 驱动交互,每个测试使用 userEvent.setup(),而不是触发原始事件,使测试重现浏览器的事件序列。对每个交互和异步断言都使用 await——未 await 的交互会针对更新前的渲染结果进行断言,因此异步 UI 应使用 findBy*。

覆盖空状态、错误状态和加载/异步状态,而不仅是正常路径。通过为单个测试覆盖 MSW handler 来产生错误状态,而不是修改共享的 handler 集合。

当所需的 UI 状态、可访问名称或外部契约未知时,应停止对该断言的测试设计,并指出所需的 UI 规范、验收标准、实现契约或用户决策。可继续编写预期行为已明确的独立断言。

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Frontend Typescript Testing AI skill do?

使用仓库已配置的 React 测试与浏览器测试工具(包括 RTL、MSW、Vitest,以及存在时的 Playwright)设计前端测试。适用于新增或评审组件测试、加载/错误状态测试、集成测试或前端 E2E 测试时。

Why use Frontend Typescript Testing on TypingMind?

Because you install it once and use it with any model. Frontend Typescript Testing is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Frontend Typescript Testing in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/shinpr/ai-coding-project-boilerplate/tree/main/.claude/skills-zh-CN/frontend-typescript-testing. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Frontend Typescript Testing?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Frontend Typescript Testing?

As many as you like. As long as a model supports skills, you can use Frontend Typescript Testing with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Frontend Typescript Testing AI skill free?

Yes. It is published on GitHub by shinpr under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇