📝 Disallow nested assertions.
💼 This rule is enabled in the ✅ recommended config.
Disallow nesting assertions, such as using an assertion as an argument to another assertion or putting assertions inside a t.throws() callback.
Nested assertions are confusing and error-prone. For example, assertions inside t.throws() will have their failures caught by throws, and assertions used as arguments make the code harder to read.
import test from 'ava';
// ❌
test('main', t => {
t.is(t.throws(() => foo()).message, 'expected');
});
// ✅
test('main', t => {
const error = t.throws(() => foo());
t.is(error.message, 'expected');
});
// ❌
test('main', t => {
t.throws(() => {
t.is(1, 2);
});
});
// ✅
test('main', t => {
t.throws(() => foo(), {message: 'expected'});
});