6

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.

4

2 に答える 2

0

これは、mocha「実行可能」がrequiremocha 関数 ( describe、およびit) を使用するために必要な s でテストをラップするためです。ディレクトリ内のmochaとを見て_mochaください。node_modules/mocha/bin

一方cloud9、純粋なnode実行可能ファイルを使用してすべてのシンボルを解決しようとするため、すべてを手動で解決する必要がありますrequire

于 2012-11-28T09:53:08.287 に答える