Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(valid-title-rule): elaborate valid-title rule properties docs #350

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
```