Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 1.66 KB

test-title-format.md

File metadata and controls

72 lines (51 loc) · 1.66 KB

Ensure test titles have a certain format (ava/test-title-format)

🚫 This rule is disabled in the ✅ recommended config.

Translations: Français

This rule is useful when you want to make sure all test titles match a common pattern to increase readability when tests fail.

For example, titles like 'Should throw when invalid.', 'Should fail when called.' or 'Should pass when using any number.' could be enforced with the following pattern '^Should (pass|fail|throw) when [\\w ]+\\.$' (Note the escaped \).

Fail

/* eslint ava/test-title-format: ["error", {format: "^Should"}] */
const test = require('ava');

test('Not starting with `Should`', t => {
	t.pass();
});
/* eslint ava/test-title-format: ["error", {format: "\\.$"}] */
const test = require('ava');

test('Doesn\'t end with a dot', t => {
	t.pass();
});

Pass

/* eslint ava/test-title-format: ["error", {format: "^Should"}] */
const test = require('ava');

test('Should pass tests', t => {
	t.pass();
});

test('Should behave as expected', t => {
	t.pass();
});
/* eslint ava/test-title-format: ["error", {format: "\\.$"}] */
const test = require('ava');

test('End with a dot.', t => {
	t.pass();
});

Options

This rule supports the following options:

format: A regular expression string to match against the test titles.

You can set the options like this:

"ava/test-title-format": [
	"error",
	{
		"format": "^Should"
	}
]