diff --git a/docs/jest.html b/docs/jest.html index f49fc414..0b8e2d9d 100644 --- a/docs/jest.html +++ b/docs/jest.html @@ -37,7 +37,9 @@
Jest 是一款优雅、简洁的 JavaScript 测试框架。
Jest 是一款优雅、简洁的 JavaScript 测试框架。
无需配置
大多数 JS 项目中即装即用,无需配置快照
轻松编写持续追踪大型对象的测试,并在测试旁或代码内显示实时快照。代码覆盖
无需其他操作,您仅需添加 --coverage
参数来生成代码覆盖率报告。npm install --save-dev jest
+
+Add to package.json
"scripts": {
+ "test": "jest"
+}
+
+运行你的测试
+npm test -- --watch
+
+查看: Getting started
+describe('My work', () => {
+ test('works', () => {
+ expect(2).toEqual(2)
+ })
+})
+
+describe('My work', () => {
+ it('works', () => { // `it`是`test`的别名
+ ···
+ })
+})
+
+describe('makePoniesPink', () => {
beforeAll(() => {
/* 在所有测试之前运行 */
@@ -67,6 +98,58 @@
})
})
+describe.only(···)
+
+it.only(···)
+// 别名: fit()
+
+查看: test.only
+Flag | Description |
---|---|
--coverage | 查看测试覆盖率摘要 |
--detectOpenHandles | 查看未关闭端口的摘要 |
--runInBand | 一个接一个地运行所有测试 |
--bail,-b | 失败跳出测试 |
更多参数查看 Jest CLI Options
+describe.skip(···)
+
+it.skip(···)
+// 别名: xit()
+
+查看: test.skip
+expect(value).not.toBe(value)
+ .toEqual(value)
+ .toBeTruthy()
+// Errors 测试
+expect(value).toThrow(error)
+ .toThrowErrorMatchingSnapshot()
+
expect(42).toBe(42) // 严格相等 (===)
@@ -517,7 +600,7 @@
})
describe.each() 文档、test.each() 文档
-describe.skip('makePoniesPink'...