-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
Would be good to have a rule to prevent people from mistakenly doing async operations in a sync test test().
A common pitfall is doing:
test(t => {
fetch().then(data => {
t.is(data, 'foo');
});
});Here they forgot to return the promise, so AVA treats it as a synchronous test.
It should have been:
test(t => {
return fetch().then(data => {
t.is(data, 'foo');
});
});We could look for assertions inside .then() that isn't returned. Might need code path analysis for less obvious cases.
We could potentially detect incorrect usage of callbacks here too:
test(t => {
fetch((err, data) => {
t.is(data, 'bar');
});
});Here we could detect that there are assertions inside a callback with a err argument first.
This should have been:
test.cb(t => {
fetch((err, data) => {
t.is(data, 'bar');
t.end();
});
});Metadata
Metadata
Assignees
Labels
No labels