Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 1.05 KB

use-t-throws-async-well.md

File metadata and controls

35 lines (24 loc) · 1.05 KB

Ensure that t.throwsAsync() and t.notThrowsAsync() are awaited (ava/use-t-throws-async-well)

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

When you use the t.throwsAsync() and t.notThrowsAsync() assertions, you must await the promise they return. If the test function completes before the assertions do, the test will fail.

This rule is fixable inside async functions. It will insert await before t.throwsAsync() and t.notThrowsAsync().

Fail

import test from 'ava';

test('main', t => {
	t.throwsAsync(somePromise);
	t.notThrowsAsync(somePromise);
});

Pass

import test from 'ava';

test('main', async t => {
	await t.throwsAsync(somePromise);
	await t.notThrowsAsync(somePromise);
	const p = t.throwsAsync(somePromise);
	t.throwsAsync(somePromise).then();
});