2
const supertest = require('supertest-as-promised');  
const expect = require('chai').expect;  

const request = supertest(process.env.BASE_URI);`

I am getting this ESLint error:

'expect' is assigned a value but never used'

for expect statement. What changes could I make to get rid of these errors from my all .js files?

Quango
  • 12,338
  • 6
  • 48
  • 83
Zorro
  • 57
  • 1
  • 8
  • See also https://stackoverflow.com/questions/37558795/nice-way-to-get-rid-of-no-unused-expressions-linter-error-with-chai – Suzana Mar 02 '23 at 14:58
  • See also https://stackoverflow.com/questions/37558795/nice-way-to-get-rid-of-no-unused-expressions-linter-error-with-chai – Suzana Mar 02 '23 at 14:58

2 Answers2

0

You are encountering the no-unused-vars rule from ESLint. You can read more about that from their documentation.

The reason ESLint is warning about you about this is that you've declared expect and assigned a value to it.

const expect = require('chai').expect; 

However you haven't used it anywhere.

To get rid of the error you need to use expect somewhere.

describe('A test', () => {
  it('should do something', () => {
    expect(something).to.be.true;
  });
});
Wing
  • 8,438
  • 4
  • 37
  • 46
  • The example given as improvement – `expect(something).to.be.true` – triggers the ESLint warning [`no-unused-expressions`](https://eslint.org/docs/rules/no-unused-expressions). – bignose Apr 03 '18 at 06:06
-1

Can use this in .eslint file

{
"rules": {
    "no-unused-vars": ["error", { "vars": "local", "args": "after-used", "ignoreRestSiblings": true }]
  }
}

For more info check this link http://eslint.org/docs/rules/no-unused-vars

Mohit Verma
  • 1,620
  • 2
  • 20
  • 30