Jest
一句话解释
Jest 是大多数 popular JavaScript 测试框架 — 它包含一切: 测试 runner, assertions, mocks, snapshots, and coverage.
用大白话说
Jest 是 batteries-包含测试框架创建通过 Facebook (Meta). 它's 大多数 popular choice for JavaScript and React 测试因为一切工作 out 的 box.
What Jest 包含:
- Test runner: discovers and 运行你的测试
- Assertion library: expect() and matchers 如 toBe, toEqual
- Mocking: jest.fn(), jest.mock(), jest.spyOn()
- Snapshot testing: toMatchSnapshot()
- Code coverage: 构建-in coverage reports
- Parallel execution: 运行测试 in parallel 通过默认
You don't 需要到 assemble 不同库 — 安装 Jest and 你're ready. 这个 simplicity 制作它 great for 初学者. trade-off 是它's heavier than 一些 alternatives and 能是 slower for 大项目.
示例
javascript
// Everything in one package
test('example', () => {
const mock = jest.fn().mockReturnValue(42);
expect(mock()).toBe(42);
expect(mock).toHaveBeenCalled();
});Jest provides 测试(), expect(), and jest.fn() 所有 in one 框架.
相关术语
相关资源
相关课程
- Jest 基础
获取开始使用 Jest.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。