Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 769 Bytes

prefer-async-await.md

File metadata and controls

31 lines (20 loc) · 769 Bytes

Prefer using async/await instead of returning a Promise

Translations: Français

AVA comes with built-in support for async functions (async/await). This allows you to write shorter and clearer tests.

This rule will report an error when it finds a test that returns an expression that looks like a Promise (containing a .then() call), which could be simplified by using the async/await syntax.

Fail

import test from 'ava';

test(t => {
	return foo().then(res => {
		t.is(res, 1);
	});
});

Pass

import test from 'ava';

test(async t => {
	t.is(await foo(), 1);
});