Skip to content

Instantly share code, notes, and snippets.

@TravelingTechGuy
Created June 12, 2015 15:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TravelingTechGuy/d1304e957bdee37b8239 to your computer and use it in GitHub Desktop.
Save TravelingTechGuy/d1304e957bdee37b8239 to your computer and use it in GitHub Desktop.
Bypass ESLint no-unused-vars error for Should in a Mocha test
// Without line 9 hack, linting the file throws: 5:4 error should is defined but never used no-unused-vars
'use strict';
var debug = require('debug')('test:myModel');
var should = require('should');
var security = require('../models/myModel');
before((done) => {
should; //bypass ESLint no-unused-var error
done();
});
describe('Security tests', () => {
let baz = 'blahblah'
it('should do foo', () => {
let result = model.foo(baz, 64);
debug(result);
result.should.not.be.empty; //not considered use of `should`
result.length.should.equal(64); //not considered use of `should`
});
it('should do bar', () => {
result = model.bar(baz);
debug(result);
result.should.not.be.empty; //not considered use of `should`
result.should.have.property('error'); //not considered use of `should`
result.error.should.be.false; //not considered use of `should`
result.should.have.property('data'); //not considered use of `should`
result.data.should.equal(baz); //not considered use of `should
});
...//more tests
});
@mrchief
Copy link

mrchief commented Sep 13, 2016

You don't need this hack. Simply say require('should'); instead of var should = require('should');

@tamj0rd2
Copy link

@mrchief you hero!

@fluxsauce
Copy link

I don't fully agree with @mrchief as a test like:

should.not.exist(something());

won't work.

Instead, just configure ESLint correctly.

  "rules": {
    "no-unused-vars": [
      "error",
      { "varsIgnorePattern": "should\|expect" }
    ]
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment