Unannounced variable warning in Mocha tests in Cloud9

I'm new to node.js and the Mocha framework for unit testing, but I created a couple of tests in the cloud9 IDE to see how it works. The code is as follows:

var assert = require("assert"); require("should"); describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present', function(){ assert.equal(-1, [1,2,3].indexOf(5)); assert.equal(-1, [1,2,3].indexOf(0)); }); }); }); describe('Array', function(){ describe('#indexOf()', function(){ it('should return the index when the value is present', function(){ assert.equal(1, [1,2,3].indexOf(2)); assert.equal(0, [1,2,3].indexOf(1)); assert.equal(2, [1,2,3].indexOf(3)); }); }); }); 

Testing works if I find mocha in the console, but the IDE shows warnings in the lines where “describe” and “this” because it says that the variable has not been declared (“undeclared variable”).

It is interesting that I do these tests to avoid warnings.

Thanks.

+6
source share
2 answers

In cloud9, you can add a hint for globals as a comment at the top of the file and remove the warnings. eg.

 **/* global describe it before */** var expect = require('chai').expect; describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present', function(){ expect(true).to.equal(true); }) }) }) 
+2
source

That, since mocha "executable" completes your test in require , you must use the mocha functions ( describe and it ). Take a look at mocha and _mocha in the node_modules/mocha/bin .

cloud9 , cloud9 other hand, tries to resolve all characters using a pure node executable, so you must require all manually.

0
source

All Articles