I'm using mocha and chai.should assertion library to unit test my OSS npm module. But eslint [v3.18.0^] warns at the should declaration in the code about it not being used
const should = chai.should();
Lint Warning 'should' is assigned a value but never used.
We have mocha as an environment in the .eslintrc. This warning appears despite there being atleast seven assertion statements in my test file like below that have "should" in them.
return sampleModule.getSomeFunction('dummy_accesss_token', 'dummy_event_id').should.eventually.be.eql([]);
I'm aware of the following SO issue which talks about other assertion statments which are never declared while a reply[which was not even declared as the answer] to the query had someone created a plugin to overcome this.
But my basic premise , isnt this a bug in eslint? Atleast "should" should :-) not be flagged since its being used in code [multiple times in my case].
isnt this a bug in eslint?
No, because you are not using the variable called should
.
You're using a getter called should
that chai.should()
adds to Object.prototype
, but that's not the same as using the variable.
You can still use that variable, for instance like this:
should.exist(...);
should.not.exist(...);
But you're probably not doing that.
So to get rid of the warning, don't do this:
const should = chai.should();
But do this:
chai.should();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With