Skip to content

Commit

Permalink
Document addition of custom message for valid-test-description rule
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgoisMickael committed Aug 21, 2019
1 parent 6593dc4 commit 84a4cf8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions docs/rules/valid-test-description.md
@@ -1,25 +1,30 @@
# Match test descriptions against a pre-configured regular expression (valid-test-description)

This rule enforces the test descriptions to follow the desired format.
This rule enforces the test descriptions to follow the desired format.

## Rule Details

By default, the regular expression is configured to be "^should" which requires test descriptions to start with "should".
By default, the regular expression is configured to be "^should" which requires test descriptions to start with "should".
By default, the rule supports "it", "specify" and "test" test function names, but it can be configured to look for different test names via rule configuration.

Example of a custom rule configuration:

```js
rules: {
"mocha/valid-test-description": ["warn", "mypattern$", ["it", "specify", "test", "mytestname"]]
"mocha/valid-test-description": ["warn", "mypattern$", ["it", "specify", "test", "mytestname"], "custom error message"]
},
// OR
rules: {
"mocha/valid-test-description": ["warn", { pattern: "mypattern$", testNames: ["it", "specify", "test", "mytestname"], message: 'custom error message' }]
},
```

where:

* `warn` is a rule error level (see [Configuring Rules](http://eslint.org/docs/user-guide/configuring#configuring-rules))
* `mypattern$` is a custom regular expression pattern to match test names against
* `["it", "specify", "test", "mytestname"]` is an array of custom test names
* `["it", "specify", "test", "mytestname"]` is an array of custom test names
* `custom error message` a custom error message to describe your pattern

The following patterns are considered warnings (with the default rule configuration):

Expand Down

0 comments on commit 84a4cf8

Please sign in to comment.