4

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].

Community
  • 1
  • 1
indcoder
  • 435
  • 1
  • 4
  • 11

1 Answers1

11

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();
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • Thanks @robertklep . Reading your comment and this is further reinforced in the chai guide http://chaijs.com/guide/styles/ – indcoder May 06 '17 at 17:45