mcpField
J
jest

jest

github.com/christopher-buss测试与质量872 次安装4 周前更新
代码仓库

关于 jest

jest 是 Jest Roblox 的技能参考;Jest Roblox 是面向 Roblox 的 Jest Luau 移植版。它说明适配后的 API 及其与 JavaScript Jest 的差异,并涵盖测试、模拟、快照和基准测试。

主要功能

  1. 01说明 Luau 特有的 Jest 差异
  2. 02介绍测试结构与匹配器
  3. 03记录异步和快照测试
  4. 04说明计时器与模块模拟
  5. 05提供基准测试指南

适用场景

  1. 01编写 Roblox Luau 测试
  2. 02将 Jest 示例适配到 Luau
  3. 03模拟模块和计时器
  4. 04设置快照测试

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/christopher-buss/skills --skill jest

安装后在 Claude Code 中输入/jest确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

GENERATION.md
references/
advanced-benchmarking.md
core-asymmetric-matchers.md
core-configuration.md
core-deviations.md
core-matchers.md
core-mocking.md
core-test-structure.md
feature-async-testing.md
feature-custom-matchers.md
feature-global-mocks.md
feature-jest-extended.md
feature-module-mocking.md
feature-snapshot-testing.md
feature-test-filtering.md
feature-timer-mocks.md

详细介绍

基于 Jest Roblox v3.x,生成于 2026-02-07。

Jest Roblox 是面向 Roblox 平台的 Jest Luau 移植版。它紧密遵循上游 Jest API,但由于 Luau 语言限制,存在一些关键差异。

与 JS Jest 的关键差异:

  • 使用 .never 而不是 .not(保留关键字)
  • jest.fn() 返回两个值:mock 对象和转发函数
  • 在 Luau 中,0、""、{} 都是真值(只有 false 和 nil 是假值)
  • 必须显式导入所有全局变量(describe、expect、jest 等)
  • .each 使用表语法,而不是标记模板字面量
  • 自定义匹配器将 self 作为第一个参数

使用此代码库时,请先阅读 core-deviations。

核心参考

主题描述参考
差异Luau/Roblox 与 JS Jest 的所有差异core-deviations
测试结构describe、test/it、钩子、.each、.only/.skipcore-test-structure
匹配器toBe、toEqual、toContain、toThrow、mock 匹配器core-matchers
非对称匹配器expect.anything/any/nothing/callable、.resolves/.rejectscore-asymmetric-matchers
Mockjest.fn()、spyOn、mock.calls、返回值core-mocking
配置jest.config.lua、runCLI、报告器、选项core-configuration

功能

测试模式
主题描述参考
异步测试Promise、done 回调、.resolves/.rejectsfeature-async-testing
自定义匹配器expect.extend()、self 参数、isNeverfeature-custom-matchers
快照测试toMatchSnapshot、属性匹配器、序列化器feature-snapshot-testing
测试筛选testMatch、testPathPattern、testNamePatternfeature-test-filtering
Mock
主题描述参考
计时器 MockuseFakeTimers、Roblox 计时器、engineFrameTimefeature-timer-mocks
全局 Mockjest.globalEnv、spyOn 全局变量、库 Mockfeature-global-mocks
模块 Mockingjest.mock()、isolateModules、resetModulesfeature-module-mocking
扩展匹配器
主题描述参考
Jest Extended当核心匹配器表达能力不足时:精确布尔值、范围、成员资格、条目、调用顺序、副作用feature-jest-extended
高级
主题描述参考
基准测试benchmark()、Reporter、Profiler、CustomReportersadvanced-benchmarking

评论

支持 Markdown