-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Labels
Description
I'm seeing this kind of error more and more in our codebase at work
test('foo', t => {
foo.bar()
.then(baz => {
});
});
The problem being that we use Promises in this test and that we don't return it, meaning that the test will in most cases pass even if the assertions in the .then
should fail later in the execution.
Therefore I'm proposing a rule (no-unreturned-promise
?) that reports an error when a test contains a Promise, but does not return anything. This should not affect callback tests test.cb(...)
or tests with an async function.
We already have code to detect Promises (should we also add support for detecting catch
?), so we could use that (and move it to eslint-ast-utils
later on ;) ).
Invalid
test('foo', t => {
foo.bar()
.then(baz => {
t.fail(); // should fail but won't
});
});
Valid
test('foo', t => {
return foo.bar() // was returned
.then(baz => {
});
});
test('foo', t => {
foo.bar(); // no promises
});
test.cb('foo', t => { // callback test
foo.bar()
.then(baz => {
});
});
test('foo', async t => { // async implementation
foo.bar()
.then(baz => {
});
});