AgentSkillsCN

jest

使用 Jest Roblox 测试 Roblox/Luau 代码。适用于在 Luau 中编写测试、模拟函数、断言数值,或配置测试套件时使用。注意:这不是 JavaScript Jest——它使用 `.never` 代替 `.not`,`jest.fn()` 返回两个值,其中 0 被视为真值。

SKILL.md
--- frontmatter
name: jest
description:
    Testing Roblox/Luau code with Jest Roblox. Use when writing tests, mocking
    functions, asserting values, or configuring test suites in Luau. NOT
    JavaScript Jest — uses .never instead of .not, jest.fn() returns two values,
    0 is truthy.
metadata:
    author: Christopher Buss
    version: "2026.2.7"
    source:
        Generated from https://github.com/Roblox/jest-roblox, scripts located at
        https://github.com/christopher-buss/skills

Based on Jest Roblox v3.x, generated 2026-02-07.

Jest Roblox is a Luau port of Jest for the Roblox platform. It closely follows the upstream Jest API but has critical deviations due to Luau language constraints.

Critical deviations from JS Jest:

  • .never instead of .not (reserved keyword)
  • jest.fn() returns two values: mock object + forwarding function
  • 0, "", {} are truthy in Luau (only false and nil are falsy)
  • All globals (describe, expect, jest, etc.) must be explicitly imported
  • .each uses table syntax, not tagged template literals
  • Custom matchers take self as first parameter

Read core-deviations first when working with this codebase.

Core References

TopicDescriptionReference
DeviationsAll Luau/Roblox differences from JS Jestcore-deviations
Test Structuredescribe, test/it, hooks, .each, .only/.skipcore-test-structure
MatcherstoBe, toEqual, toContain, toThrow, mock matcherscore-matchers
Asymmetric Matchersexpect.anything/any/nothing/callable, .resolves/.rejectscore-asymmetric-matchers
Mockingjest.fn(), spyOn, mock.calls, return valuescore-mocking
Configurationjest.config.lua, runCLI, reporters, optionscore-configuration

Features

Testing Patterns

TopicDescriptionReference
Async TestingPromises, done callbacks, .resolves/.rejectsfeature-async-testing
Custom Matchersexpect.extend(), self parameter, isNeverfeature-custom-matchers
Test FilteringtestMatch, testPathPattern, testNamePatternfeature-test-filtering

Mocking

TopicDescriptionReference
Timer MocksuseFakeTimers, Roblox timers, engineFrameTimefeature-timer-mocks
Global Mocksjest.globalEnv, spyOn globals, library mocksfeature-global-mocks
Module Mockingjest.mock(), isolateModules, resetModulesfeature-module-mocking

Advanced

TopicDescriptionReference
Benchmarkingbenchmark(), Reporter, Profiler, CustomReportersadvanced-benchmarking