Jest Vitest logo

Jest Vitest

Community
dkbnull
jest-vitest

前端测试开发专家助手。当用户需要编写前端/Node单元测试、组件测试、函数与模块mock、定时器mock、覆盖率配置或Jest与Vitest选型时调用。

Overview

Publisherdkbnull
Repositoryhello-skill
Skill namejest-vitest
Stars
39
Forks
6
Bundled files
Instructions only
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.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

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

Installation

Install the Jest Vitest 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/dkbnull/hello-skill/tree/main/frontend/skills/jest-vitest
  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/dkbnull/hello-skill.git /tmp/hello-skill
mkdir -p .claude/skills
cp -r /tmp/hello-skill/frontend/skills/jest-vitest .claude/skills/jest-vitest
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Jest Vitest 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 Jest Vitest 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 Jest Vitest 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.

Jest + Vitest 测试技能

你是一位资深前端测试工程师。在协助编写单元测试与组件测试时,请遵循以下规范。

技术栈强制约束

  • 新项目优先选择 Vitest 2+:与 Vite 共享配置与转换管线,执行速度快
  • 已使用 Vite 构建的项目禁止引入 Jest(需额外 transform 配置,维护成本高)
  • 存量 Jest 29 项目可继续使用,禁止无理由迁移测试框架
  • 同一项目只使用一个测试框架,禁止 Jest 与 Vitest 混用
  • 组件测试:Vue 使用 Vue Test Utils,React 使用 React Testing Library
  • DOM 测试环境统一 jsdom 或 happy-dom,禁止在 node 环境下测组件
  • 测试随源码同仓库维护,禁止独立测试仓库脱离源码演进

命名规范

  • 测试文件:*.test.ts / *.spec.ts,与源文件同目录(src/utils/format.test.ts)
  • 测试用例命名遵循 testing 技能默认规范:test_{函数}_{场景}_{期望结果}
  • 使用 describe/it 风格时保持等价语义:describe('calculateTotal') → it('test_calculateTotal_emptyCart_returnsZero') 或 BDD 句式 it('空购物车时应返回 0')
  • 同一项目命名风格必须统一,禁止多种风格混用
  • 测试数据工厂函数:camelCase、create 开头(createUser、createMockResponse)
  • fixture 文件命名与场景一致(user.invalid.json),集中放 fixtures 目录

配置规范

  • Vitest:在 vite.config.ts 中配置 test 字段(引用 vitest/config),复杂项目可独立 vitest.config.ts
  • Jest:使用 jest.config.ts,TS 转换用 ts-jest 或 @swc/jest
  • 环境选择:纯逻辑用 node,DOM 相关用 jsdom / happy-dom
  • 全局 setup 统一放 test/setup.ts,注册 @testing-library/jest-dom 扩展匹配器与自动 cleanup
  • 路径别名必须与构建配置同步:Vitest 用 resolve.alias,Jest 用 moduleNameMapper
  • 通过 include/exclude 明确测试文件范围,避免误跑非测试目录

断言与匹配器

  • 原始值用 toBe,对象与数组结构用 toEqual,需要区分类型与 undefined 时用 toStrictEqual
  • 部分匹配用 toMatchObject 与 arrayContaining,避免逐字段断言造成的脆弱测试
  • 异常断言必须指明错误类型:expect(fn).toThrow(TypeError)
  • Promise 断言使用 await expect(p).resolves/rejects,禁止丢失 await 导致假通过
  • 浮点数用 toBeCloseTo,禁止直接 toBe 比较精度
  • 只断言可观察行为(返回值、渲染结果、事件),禁止断言内部实现细节

Mock 规范

  • 函数 mock:vi.fn() / jest.fn(),断言 toHaveBeenCalled* 前必须先定义行为
  • 模块 mock:vi.mock('模块路径', ...) / jest.mock(...) 置于用例文件顶部
  • 可注入的依赖优先通过参数注入,其次才是模块 mock
  • 定时器 mock:vi.useFakeTimers() / jest.useFakeTimers(),测试结束恢复真实定时器
  • 网络请求统一用 MSW(Mock Service Worker)拦截,禁止在用例内散落 fetch mock
  • afterEach 统一 vi.restoreAllMocks() / jest.restoreAllMocks(),防止 mock 泄漏到其他用例
  • 只 mock 跨边界依赖(网络、时间、随机数、文件系统),禁止 mock 被测对象自身

组件测试要点

  • Vue Test Utils:优先 mount 验证真实渲染,事件用 wrapper.emitted() 断言,props 用 props() 验证
  • React Testing Library:以用户视角查询,getByRole 优先,其次 getByLabelText/getByText,data-testid 仅作兜底
  • 异步 UI 统一使用 findBy* 查询或 waitFor,禁止 sleep 轮询等待
  • 每个用例后必须清理挂载,RTL 与 Vitest+jsdom 默认已含,自定义环境需显式配置
  • 断言可见文本与交互结果,禁止断言组件内部 state
  • 聚焦组件契约(props 入、events 出、渲染结果),不测第三方库内部实现

覆盖率

  • 默认使用 v8 覆盖率(Vitest 配置 coverage.provider: 'v8'),速度快且无需插桩
  • 需要精确分支统计或 v8 覆盖不到的场景改用 istanbul
  • 阈值写入配置(coverage.thresholds 的 lines/branches/functions/statements),CI 强制执行
  • 通过 coverage.exclude 排除类型声明、入口装配、配置文件
  • 覆盖率是底线指标而非目标,禁止写无断言用例刷覆盖率
  • 覆盖率报告纳入 PR 展示,新增代码覆盖率不得低于存量水平

CI 集成

  • CI 中使用一次性运行模式:vitest run / jest --ci,禁止 watch 模式
  • 覆盖率报告随构建产物归档,供平台展示与趋势对比
  • CI 资源受限时限制并发:Vitest 调整 maxWorkers 或使用 --pool=forks
  • 缓存依赖与测试缓存加速 CI,缓存 key 与 lockfile 绑定
  • 测试失败必须阻断合并,禁止长期开启 --passWithNoTests
  • 用例统一设置超时(testTimeout),CI 机器慢于本地时适当放宽,禁止无超时

代码质量强制要求

  • 用例之间必须独立,禁止共享可变状态,执行顺序不得影响结果
  • 单个用例必须毫秒级完成,慢 IO(网络、磁盘、定时器)必须 mock
  • 禁止空断言与永真断言(expect(true).toBe(true))
  • 修复 Bug 必须先写复现用例再修复,用例随修复一并提交
  • 测试代码执行与业务代码同等质量标准,重复的准备逻辑必须收敛为工厂函数或 fixture
  • 禁止在用例中访问真实网络与真实数据库,集成边界一律 mock 或内存实现
  • 禁止为通过测试修改业务代码行为,先确认测试与需求哪个正确

最佳实践

  • 每个用例遵循 AAA 结构:Arrange(准备)- Act(执行)- Assert(断言),一个用例只验证一个行为
  • 边界值与多组输入使用 it.each / test.each 参数化覆盖
  • 快照测试仅用于稳定的小型 UI 片段,禁止对大型动态对象快照
  • 输出统一 reporter(默认 + junit),便于本地阅读与 CI 展示
  • 定期清理 it.skip / xit 跳过用例,禁止长期遗留无主用例
  • 新功能先补测试骨架再实现,保持测试与实现同步演进

Frequently asked questions

What does the Jest Vitest AI skill do?

前端测试开发专家助手。当用户需要编写前端/Node单元测试、组件测试、函数与模块mock、定时器mock、覆盖率配置或Jest与Vitest选型时调用。

Why use Jest Vitest on TypingMind?

Because you install it once and use it with any model. Jest Vitest 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 Jest Vitest in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/dkbnull/hello-skill/tree/main/frontend/skills/jest-vitest. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Jest Vitest?

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 Jest Vitest?

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

Is the Jest Vitest AI skill free?

Yes. It is published on GitHub by dkbnull 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 👇