Skip to content

Commit 48a6c3d

Browse files
authored
docs: polish expect api (#576)
1 parent d7f60c0 commit 48a6c3d

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

website/docs/en/api/test-api/expect.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ overviewHeaders: [2, 3]
77

88
`expect` is used to assert values in tests. It provides a rich set of matchers, supports chainable modifiers, soft assertions, polling, and snapshot testing.
99

10+
You can import the `expect` API from the `@rstest/core` package:
11+
12+
```ts
13+
import { expect, test } from '@rstest/core';
14+
15+
test('should add two numbers correctly', () => {
16+
expect(1 + 1).toBe(2);
17+
expect(1 + 2).toBe(3);
18+
});
19+
```
20+
21+
You can also get the `expect` API from the [test context](/api/test-api/test#testcontext), which is helpful for tracing assertion belonging in concurrent tests.
22+
23+
```ts
24+
import { test } from '@rstest/core';
25+
26+
test('should add two numbers correctly', ({ expect }) => {
27+
expect(1 + 1).toBe(2);
28+
expect(1 + 2).toBe(3);
29+
});
30+
```
31+
1032
## expect
1133

1234
- **Type:** `<T>(actual: T, message?: string) => Assertion<T>`

website/docs/en/api/test-api/test.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ export interface TestContext {
188188
expect: Expect;
189189
/** The `onTestFinished` hook bound to the current test */
190190
onTestFinished: OnTestFinished;
191+
/** The `onTestFailed` hook bound to the current test */
192+
onTestFailed: OnTestFailed;
191193
}
192194
```
193195

194-
You can extend `TestContext` with custom fixtures using `test.extend`.
196+
You can also extend `TestContext` with custom fixtures using `test.extend`.

website/docs/zh/api/test-api/expect.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ overviewHeaders: [2, 3]
77

88
`expect` 用于在测试中创建断言。Rstest 提供了丰富的 API 及匹配器,支持轮询、快照断言等。
99

10+
你可以从 `@rstest/core` 包中导入 `expect` API:
11+
12+
```ts
13+
import { expect, test } from '@rstest/core';
14+
15+
test('should add two numbers correctly', () => {
16+
expect(1 + 1).toBe(2);
17+
expect(1 + 2).toBe(3);
18+
});
19+
```
20+
21+
你也可以从 [测试上下文](/api/test-api/test#testcontext) 中获取 `expect` API,这有助于在并行测试中准确追踪断言的来源。
22+
23+
```ts
24+
import { test } from '@rstest/core';
25+
26+
test('should add two numbers correctly', ({ expect }) => {
27+
expect(1 + 1).toBe(2);
28+
expect(1 + 2).toBe(3);
29+
});
30+
```
31+
1032
## expect
1133

1234
- **类型:** `<T>(actual: T, message?: string) => Assertion<T>`

website/docs/zh/api/test-api/test.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ export interface TestContext {
177177
expect: Expect;
178178
/** The `onTestFinished` hook bound to the current test */
179179
onTestFinished: OnTestFinished;
180+
/** The `onTestFailed` hook bound to the current test */
181+
onTestFailed: OnTestFailed;
180182
}
181183
```
182184

183-
你可以通过 `test.extend` 方法通过自定义 fixture 的方式来扩展测试上下文。
185+
你也可以通过 `test.extend` 方法通过自定义 fixture 的方式来扩展测试上下文。

0 commit comments

Comments
 (0)