Created
June 12, 2015 15:33
-
-
Save TravelingTechGuy/d1304e957bdee37b8239 to your computer and use it in GitHub Desktop.
Bypass ESLint no-unused-vars error for Should in a Mocha test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 you hero!
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
You don't need this hack. Simply say
require('should');
instead ofvar should = require('should');