Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Standard Style does not recognize Mocha

I have a Mocha test file that looks like this:

var expect = require('chai').expect
var muting = require('../muting')

describe('muting', function () {
  describe('init()', function () {
    it('should inject an object into twitter', function () {
      var twitter = 'twitter'
      muting.init(twitter)
      expect(muting.twitter).to.equal(twitter)
    })
  })
})

When I run mocha from the CLI, it runs the test successfully.

When I run standard (the executable for JavaScript Standard Style) I get errors on Mocha's framework functions like so:

standard: Use JavaScript Standard Style (https://github.com/feross/standard)   
c:\..\test\index.js:5:0: 'describe' is not defined.  
c:\..\test\index.js:6:2: 'describe' is not defined.  
c:\..\test\index.js:7:4: 'it' is not defined.

What's the cleanest way to make Standard not complain about these functions?

like image 769
urig Avatar asked May 03 '15 19:05

urig


People also ask

Does Standard JS work with TypeScript?

TypeScript. ts-standard is the officially supported variant for TypeScript. ts-standard supports all the same rules and options as standard and includes additional TypeScript specific rules. ts-standard will even lint regular javascript files by setting the configuration in tsconfig.

Is Mocha a JavaScript library?

Mocha - the fun, simple, flexible JavaScript test framework. Mocha is a feature-rich JavaScript test framework running on Node. js and in the browser, making asynchronous testing simple and fun.

What is standard JavaScript?

JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat.


2 Answers

I prefer to edit my .eslintrc and add mocha to env section:

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

this way my package.json file is kept clean, also vscode plugin for eslint understands it better

like image 146
Developerium Avatar answered Oct 10 '22 16:10

Developerium


Actually, you don't need to list every single global variable in your package.json

You can specify environments instead like this:

"standard": {
  "env": [ "mocha" ]
}

Source: Official ESLint configuration docs.

like image 166
Krzysztof Kaczor Avatar answered Oct 10 '22 17:10

Krzysztof Kaczor