Skip to content

Commit

Permalink
docs(valid-title-rule): elaborate valid-title rule properties docs (#350
Browse files Browse the repository at this point in the history
)
  • Loading branch information
antoinezanardi authored Jan 11, 2024
1 parent 426fc92 commit 0a4ac7d
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions docs/rules/valid-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Rule Details

This rule aims to enforce valid titles for tests.
This rule aims to enforce valid titles for `describe`, `it` and `test` titles.

## Options

Expand All @@ -19,11 +19,11 @@ This rule has an object option:
"vitest/valid-title": [
"error",
{
"ignoreTypeOfDescribeName": false,
"allowArguments": false,
"disallowedWords": ["skip", "only"],
"mustNotMatch": ["^\\s+$", "^\\s*\\d+\\s*$"],
"mustMatch": ["^\\s*\\w+\\s*$"]
"ignoreTypeOfDescribeName": false,
"allowArguments": false,
"disallowedWords": ["skip", "only"],
"mustNotMatch": ["^\\s+$", "^\\s*\\d+\\s*$"],
"mustMatch": ["^\\s*\\w+\\s*$"]
}
]
}
Expand Down Expand Up @@ -122,6 +122,14 @@ describe('foo', () => {

An array of regex strings that are required in the test title.

If you specify an array of regex strings, the check is performed on `describe`, `test` and `it` titles.

For more granular control, you can specify an object with the following properties :

- `describe`: an array of regex strings that are required in the `describe` title.
- `test`: an array of regex strings that are required in the `test` title.
- `it`: an array of regex strings that are required in the `it` title.

Examples of **incorrect** code for this rule with the `{ "mustMatch": ["^\\s*\\w+\\s*$"] }` option:

```js
Expand All @@ -142,3 +150,27 @@ describe('foo', () => {
})
})
```

Examples of **incorrect** code for this rule with the `{ "mustMatch": { "it": ["^should .+\.$"] } }` option:

```js
// The describe title is checked with the default regex, so it's valid
describe('foo', () => {
// This check fails because the title does not match the regex
it('Should be a number', () => {
expect(1).toBeNumber()
})
})
```

Examples of **correct** code for this rule with the `{ "mustMatch": { "describe": ["^\\s*\\w+\\s*$"] } }` option:

```js
// The describe title is checked with the default regex, so it's valid
describe('foo', () => {
// This check succeeds because the title matches the regex
it('should be a number.', () => {
expect(1).toBeNumber()
})
})
```

0 comments on commit 0a4ac7d

Please sign in to comment.