Cloud9中的Mochatesting中的“未声明的variables”警告

我是node.js和unit testing框架Mocha的新手,但是我已经在cloud9 IDE中创build了一些testing,以了解它是如何工作的。 代码如下所示:

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

如果我在控制台中键入mocha,testing会起作用,但IDE会在“describe”和“it”的行中显示警告,因为它说variables没有被声明(“未声明的variables”)。

我想知道我应该怎么做这些testing来避免这些警告。

谢谢。

在cloud9中,您可以在全局文件顶部添加全局提示,并删除警告。 例如

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

这是因为mocha “可执行”包装你的testing需要使用摩卡function( describeit )。 在node_modules/mocha/bin目录中查看mocha_mocha

另一方面, cloud9尝试使用纯node可执行文件parsing所有符号,因此您必须手工完成所有操作。