Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 1.11 KB

assertion-message.md

File metadata and controls

51 lines (36 loc) · 1.11 KB

Enforce or disallow assertion messages

Assertion messages are optional arguments that can be given to any assertion call to improve the error message, should the assertion fail. This rule either enforces or disallows the use of those messages.

Fail

import tap from 'tap';

/* eslint tap/assertion-message: ["error", "always"] */
tap.test('test name', t => {
	t.ok(array.includes(value));
	t.end();
});

/* eslint tap/assertion-message: ["error", "never"] */
tap.test('test name', t => {
	t.ok(array.includes(value), 'value is not in array');
	t.end();
});

Pass

import tap from 'tap';

/* eslint tap/assertion-message: ["error", "always"] */
tap.test('test name', t => {
	t.ok(array.includes(value), 'value is not in array');
	t.end();
});

/* eslint tap/assertion-message: ["error", "never"] */
tap.test('test name', t => {
	t.ok(array.includes(value));
	t.end();
});

Options

The rule takes one option, a string, which could be either "always" or "never". The default is "always".

You can set the option in configuration like this:

"tap/assertion-message": ["error", "always"]