Comments (5)
I general I like this proposal. I think the hard part of this would be detect if a promise is returned or not. Do you know how mocha does this check? Does it fail for any non falsy value that is returned or only for objects that have a then
method?
Maybe the easiest approach would be to warn on any top-level return (maybe with exceptions for return;
return undefined;
and return null;
). I think looking for the usage of calling a then
method within the return statement is probably pretty error-prone. Consider the following examples:
it('foo', function () {
// chai-as-promised assertions returns promises
return expect(promiseReturningFunction()).to.be.fulfilled;
});
it('foo', function () {
return Promise.all([ checkFoo(), checkBar() ]);
});
from eslint-plugin-mocha.
Does it fail for any non falsy value that is returned or only for objects that have a then method?
Only for Promises (so the latter). This is correct behavior for instance:
describe('foo', function() {
it('should', function(done) {
function foo() {
done();
}
setTimeout(foo, 500);
return 3;
});
});
But returning anything other than a Promise doesn't provide any value, so I'd say it's fine to warn if there is a return statement and a callback.
Maybe the easiest approach would be to warn on any top-level return
Yes, that is what I was thinking too.
maybe with exceptions for return; return undefined; and return null;
Not sure I see the point of having such statements in your tests anyway 😕
I think looking for the usage of calling a then method within the return statement is probably pretty error-prone
Same here. Sometimes you just want to call catch
, or custom Bluebird methods for instance.
from eslint-plugin-mocha.
Not sure I see the point of having such statements in your tests anyway
Maybe it is used to skip further execution of the test, but maybe you are right it is uncommon to do that anyway 😉 .
from eslint-plugin-mocha.
Maybe it is used to skip further execution of the test, but maybe you are right it is uncommon to do that anyway 😉 .
Ah, you mean something like this
it('should xyz', function() {
const res = foo();
assert(res);
if (!process.env.FOO) {
return;
}
assert(res.xyz === 'foo');
});
Would make sense if you're testing stuff conditionally based on the environment, or creating tests in a loop. You're right, I'll make the change later to ignore this when you return a nothing (return;
) or a literal value (return null/"foo"
) or undefined.
from eslint-plugin-mocha.
You're right, I'll make the change later to ignore this when you return a nothing (return;) or a literal value (return null/"foo") or undefined.
That has been done in PR #94.
from eslint-plugin-mocha.
Related Issues (20)
- false positive with non mocha hook HOT 1
- No-identical-title rule HOT 1
- Support ESLint 8.x HOT 4
- Rule proposal: no-empty-description HOT 1
- `no-mocha-arrows` fix produces invalid code with comments
- [fixed in v10.0.1] new rule `no-empty-description` definition not found in v10.0.0 ? HOT 3
- `no-empty-description` incorrectly flags non-empty descriptions. HOT 6
- Consitent rule naming
- node 12 should still be supported HOT 1
- Upgrade to ramda 0.28.0 HOT 1
- ESLint peer dependency causing issues HOT 2
- ramda 0.28.0 regression in 10.0.4 (node 17) HOT 7
- 10.0.4 caused "[DEP0148] DeprecationWarning: Use of deprecated folder mapping..." warning HOT 1
- v10.0.4 crashes on node 17 HOT 2
- False positive when test is not a mocha global HOT 1
- mocha/no-top-level-hooks with test generator function HOT 2
- Issue within ESM module HOT 1
- The `mocha/prefer-arrow-callback` rule does not work as documented
- Support function calls as custom names (to stop false warnings) HOT 2
- ESLint 9 / Flat config
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-mocha.