Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 1.69 KB

File metadata and controls

67 lines (47 loc) · 1.69 KB

ava/max-asserts

📝 Limit the number of assertions in a test.

🚫 This rule is disabled in the ✅ recommended config.

Translations: Français

Limit the amount of assertions in a test to enforce splitting up large tests into smaller ones.

Skipped assertions are counted.

Examples

/*eslint ava/max-asserts: ["error", {"max": 5}]*/
import test from 'ava';

// ❌
test('getSomeObject should define the players\' names', t => {
	const object = lib.getSomeObject();

	t.is(typeof object, 'object');
	t.is(typeof object.player, 'object');
	t.is(object.player.firstName, 'Luke');
	t.is(object.player.lastName, 'Skywalker');
	t.is(typeof object.opponent, 'object');
	t.is(object.opponent.firstName, 'Darth');
	t.is(object.opponent.lastName, 'Vader');
});

// ✅
test('getSomeObject should define the player\'s name', t => {
	const object = lib.getSomeObject();

	t.is(typeof object, 'object');
	t.is(typeof object.player, 'object');
	t.is(object.player.firstName, 'Luke');
	t.is(object.player.lastName, 'Skywalker');
});

test('getSomeObject should define the opponent\'s name', t => {
	const object = lib.getSomeObject();

	t.is(typeof object, 'object');
	t.is(typeof object.opponent, 'object');
	t.is(object.opponent.firstName, 'Darth');
	t.is(object.opponent.lastName, 'Vader');
});

Options

max

Type: integer
Default: 5

The maximum number of assertions allowed in each test.

You can set the option in configuration like this:

"ava/max-asserts": ["error", {"max": 5}]