Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.2 KB

use-true-false.md

File metadata and controls

41 lines (31 loc) · 1.2 KB

Ensure that t.true()/t.false() are used instead of t.truthy()/t.falsy() (ava/use-true-false)

💼 This rule is enabled in the ✅ recommended config.

Translations: Français

t.true() and t.false() are stricter in their checks than t.truthy() and t.falsy. For example: if you have a function foo() which normally returns true, but suddenly returns 1 instead, t.truthy(foo()) would not catch the change, but t.true(foo()) would. This rule enforces the use of the former when the tested expression is known to result in a boolean value.

Fail

const ava = require('ava');

test('foo', t => {
	t.truthy(value < 2);
	t.truthy(value === 1);
	t.truthy([1, 2, 3].includes(value));
	t.falsy(!value);
	t.truthy(!!value);
	t.truthy(Array.isArray(value));
});

Pass

const ava = require('ava');

test('foo', t => {
	t.true(value < 2);
	t.true(value === 1);
	t.true([1, 2, 3].includes(value));
	t.false(!value);
	t.true(!!value);
	t.true(Array.isArray(value));
});