Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 1.44 KB

valid-test-title.md

File metadata and controls

52 lines (36 loc) · 1.44 KB

Require test descriptions to match a pre-configured regular expression (mocha/valid-test-title)

🚫 This rule is disabled in the ✅ recommended config.

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".

Options

Example of a custom rule configuration:

rules: {
    "mocha/valid-test-title": ["warn", { pattern: "mypattern$", message: 'custom error message' }]
},

where:

  • warn is a rule error level (see Configuring Rules)
  • mypattern$ is a custom regular expression pattern to match test names against
  • custom error message a custom error message to describe your pattern

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

// bdd
it('does something', function () {});
specify('does something', function () {});

// tdd
test('does something', function () {});

These patterns would not be considered warnings:

// bdd
it('should respond to GET', function () {});
it('should do something');
specify('should respond to GET', function () {});
specify('should do something');

// tdd
test('should respond to GET', function () {});
test('should do something');