我是node.js和单元测试框架Mocha的新手,但我已经在cloud9 IDE中创建了几个测试,以了解它是如何工作的。代码如下所示:Cloud9中的Mocha测试中的“未声明的变量”警告
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));
});
});
});
测试工作,如果我在控制台输入摩卡,但IDE显示在“描述”和“它”是行警告,因为它说,该变量尚未声明(“未声明的变量”)。
我不知道该怎么做这些测试来避免警告。
谢谢。
那么我需要什么手工?因为我试图做var mocha = require(“mocha”);并将代码更改为mocha.describe ...并且警告消失,但是在执行摩卡时失败。 – Juanillo
@Juanillo我不确定这有一个简单的解决方法。您可以强制cloud9运行您的摩卡测试,但这并不能解决未声明的变量问题。 – soulcheck
好的,谢谢,我对此很好奇,因为我是这个平台的新手,但我想知道有经验的程序员是否在这种情况下做了些什么。但是,似乎其他实际项目使用了类似代码的Mocha。也许他们只是在cloud9工作时忽略这些警告,但我真的很惊讶在真正严肃的项目中可以给出警告。 – Juanillo