Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"undeclared variable" warning in Mocha tests in Cloud9

I'm new at node.js and the framework Mocha for unit testing, but I've created a couple of tests in cloud9 IDE just to see how it works. The code looks like this:

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));
    });
  });
});

The tests work if I type mocha in the console, but the IDE shows warnings in the lines where "describe" and "it" are because it says that the variable has not been declared ("undeclared variable").

I wonder what should I do these tests to avoid the warnings.

Thanks.

like image 769
Juanillo Avatar asked Nov 27 '12 22:11

Juanillo


1 Answers

In cloud9 you can add a hint for globals as a comment at the top of the file and it will remove the warnings. e.g.

**/* 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);
    })
  })
})
like image 181
lummie Avatar answered Nov 09 '22 20:11

lummie