Skip to content

Commit 4871b94

Browse files
authored
docs: update testNamePattern configuration details (#690)
1 parent 0dbdfcb commit 4871b94

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

website/docs/en/config/test/testNamePattern.mdx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Run only tests with a name that matches the regex / string.
88

99
If you set `testNamePattern` to `bar`, tests not containing the word `bar` in the test name will be skipped.
1010

11+
It should be noted that the test name consists of the test case name and the name of the test suite that wraps it. If a test suite name contains `bar`, all test cases in that test suite will be run.
12+
1113
import { Tab, Tabs } from '@theme';
1214

1315
<Tabs defaultValue='rstest.config.ts'>
@@ -24,7 +26,7 @@ export default defineConfig({
2426
testNamePattern: 'bar',
2527
});
2628
```
27-
</Tab>
29+
</Tab>
2830
</Tabs>
2931

3032
```ts
@@ -37,4 +39,21 @@ test('test foo', () => {
3739
test('test bar', () => {
3840
expect(true).toBe(true);
3941
});
42+
43+
// run all tests in this suite
44+
describe('bar', () => {
45+
it('should add two numbers correctly', () => {
46+
expect(1 + 1).toBe(2);
47+
});
48+
});
49+
```
50+
51+
If you want to exclude certain tests instead, you can use a negative regex. For example, `/^(?!.*bar).*$/` skips every test whose name contains `bar`.
52+
53+
```ts title="rstest.config.ts"
54+
import { defineConfig } from '@rstest/core';
55+
56+
export default defineConfig({
57+
testNamePattern: /^(?!.*bar).*$/,
58+
});
4059
```

website/docs/zh/config/test/testNamePattern.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
如果将 `testNamePattern` 设置为 `bar`,则测试名称中不包含 `bar` 的测试将被跳过。
1010

11+
需要注意的是,测试名称由测试用例名称和包裹它的测试套件名称组成。如果测试套件名称中包含 `bar`,则该测试套件中的所有测试用例都将被运行。
12+
1113
import { Tab, Tabs } from '@theme';
1214

1315
<Tabs defaultValue='rstest.config.ts'>
@@ -37,4 +39,21 @@ test('test foo', () => {
3739
test('test bar', () => {
3840
expect(true).toBe(true);
3941
});
42+
43+
// run all tests in this suite
44+
describe('bar', () => {
45+
it('should add two numbers correctly', () => {
46+
expect(1 + 1).toBe(2);
47+
});
48+
});
49+
```
50+
51+
如果你希望排除某些测试,可以使用负向正则表达式。例如,`/^(?!.*bar).*$/` 将排除所有名称中包含 `bar` 的测试。
52+
53+
```ts title="rstest.config.ts"
54+
import { defineConfig } from '@rstest/core';
55+
56+
export default defineConfig({
57+
testNamePattern: /^(?!.*bar).*$/,
58+
});
4059
```

0 commit comments

Comments
 (0)