How to get "should.be.false" syntax pass jslint?

node.jsJslintChai

node.js Problem Overview


I am writing JS UT for my NodeJS code. I am using Chai as the assertion library, and I prefer the should syntax. I also use jslint to check the JS file syntax, even the JS files for UT.

Now I have a problem with jslint and Chai. In Chai, you can use:

myvalue.should.be.true;

But jslint give me:

#1 Expected an assignment or function call and instead saw an expression.

I know jslint comes with many options, but I just cannot find the right one to turn off this check.

node.js Solutions


Solution 1 - node.js

Just to make it clear to other readers:

You can add /*jshint expr: true*/ to the top of the test files, so it only allows it in the test files.

In the rare case that you use that kind of expressions in your code, you can add the expr: true option to the jshint config options.

Solution 2 - node.js

You can also use myvalue.should.equal(true) instead.

Solution 3 - node.js

It turns our jslint is unable to solve my problem. And due to many restrictions of jslint, I turned to jshint, and the option expr saved me :P

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid S.View Question on Stackoverflow
Solution 1 - node.jsJesús CarreraView Answer on Stackoverflow
Solution 2 - node.jsBeauView Answer on Stackoverflow
Solution 3 - node.jsDavid S.View Answer on Stackoverflow