Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.73 KB

max-asserts.md

File metadata and controls

64 lines (45 loc) · 1.73 KB

Enforce a limit on the number of assertions in a test (ava/max-asserts)

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

Fail

/*eslint ava/max-asserts: ["error", 5]*/
const test = require('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');
});

Pass

const test = require('ava');

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

The rule takes one option, a number, which is the maximum number of assertions for each test. The default is 5.

You can set the option in configuration like this:

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