New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rule to enforce returning promise in async tests instead of done #62
Comments
Thanks for the issue. What would be the intent of such a rule? Is it only about consistency or does it prevent some issues with the |
that would be used as a reminder of a better code made possible by the use of promises for all the project members. most our code is promise-based except tests, which mostly
|
Ok, sounds like it is a stylistic rule.I think we can do this by simply looking for the |
I have been trying to write tests this way, and it works fine for normal cases, but I'm struggling to find a good way to find that a Promise should be rejected (with or without a check on the rejection reason). Any tips on that? I think tips for that should probably appear in the rule documentation. |
promise should be rejected? what you mean? |
I mean, how do you write a test where you expect a Promise to be rejected? it('should reject when no arguments are passed', function(done) {
lib.foo()
.then(function() {
done(new Error('Expected error'));
})
.catch(function(error) {
assert.ok(error);
done();
});
}); I have trouble writing tests like these withtout the |
it('should reject when no arguments are passed', function() {
return lib.foo()
.then(function() {
assert(false);
})
.catch(function(error) {
assert.ok(error);
});
}); I think that should work. |
or using it('should reject when no arguments are passed', function() {
return expect( lib.foo() ).to.eventually.be.rejected;
}); |
@lo1tuma Unfortunately, your solution doesn't work, because the error thrown by the I actually remembered a solution that I used, which uses the two arguments of it('should reject when no arguments are passed', function() {
return lib.foo()
.then(function() {
assert(false);
}, function(error) {
assert(error);
});
}); This works. But I find using the two arguments instead of a And yes, |
Anyway, now that I have found a solution, I'm all for this rule, but the documentation should probably give tips on how to achieve this (normal case and my expected error case). |
don't know if it is possible to enforce usage of promise returns, probably not.
at least it should be possible to check that
done
argument is not used and areturn something
is used insteadThe text was updated successfully, but these errors were encountered: