Nice way to get rid of no-unused-expressions linter error with chai

后端 未结 6 1791
长发绾君心
长发绾君心 2020-12-09 07:12

In my Chai tests I often find myself wanting to use their assertions that are something like .to.be.empty, .to.be.true e.t.c., because I find them

6条回答
  •  被撕碎了的回忆
    2020-12-09 07:53

    In case anyone is stumbling upon this today, I had the same issue and found this solution on eslint documentation. In your eslint configuration file, you can specify one or several environments, which will predefine global variables for this environment. For us, it'd be mocha, and you'd configure like this in your .eslintrc.json:

    {
        "env": {
            "mocha": true
        },
        ...
        ...
        ...
    }
    

    As a result, it will remove all false positive about mocha describe, it, beforeEach, etc. without needing to completely disable eslint or completely disable any specific rule.

    Tested with ESLint v.4.11 and mocha 5.0

提交回复
热议问题