我在测试用例中提交了一个网络请求,但这有时需要超过2秒(默认超时).
如何增加单个测试用例的超时?
我正在使用Mocha来测试我的NodeJS应用程序.我无法弄清楚如何使用其代码覆盖功能.我试过谷歌搜索但没有找到任何适当的教程.请帮忙.
我用Mocha来测试我的JavaScript东西.我的测试文件包含5个测试.是否可以运行特定测试(或测试集)而不是文件中的所有测试?
我有问题让Chai expect.to.throw在我的node.js应用程序的测试中工作.测试在抛出错误时保持失败,但是如果我在try中包装测试用例并捕获并断言捕获的错误,则它可以工作.
难道expect.to.throw不喜欢的工作,我认为它应该还是什么?
it('should throw an error if you try to get an undefined property', function (done) {
var params = { a: 'test', b: 'test', c: 'test' };
var model = new TestModel(MOCK_REQUEST, params);
// neither of these work
expect(model.get('z')).to.throw('Property does not exist in model schema.');
expect(model.get('z')).to.throw(new Error('Property does not exist in model schema.'));
// this works
try {
model.get('z');
}
catch(err) {
expect(err).to.eql(new Error('Property does not exist in model schema.'));
}
done();
});
Run Code Online (Sandbox Code Playgroud)
失败:
19 …Run Code Online (Sandbox Code Playgroud) Mochatest默认尝试查找测试文件,如何指定另一个目录,例如server-test?
在我的节点应用程序中,我使用mocha来测试我的代码.在使用mocha调用许多异步函数时,我收到超时错误(Error: timeout of 2000ms exceeded.).我该如何解决这个问题?
var module = require('../lib/myModule');
var should = require('chai').should();
describe('Testing Module', function() {
it('Save Data', function(done) {
this.timeout(15000);
var data = {
a: 'aa',
b: 'bb'
};
module.save(data, function(err, res) {
should.not.exist(err);
done();
});
});
it('Get Data By Id', function(done) {
var id = "28ca9";
module.get(id, function(err, res) {
console.log(res);
should.not.exist(err);
done();
});
});
});
Run Code Online (Sandbox Code Playgroud) 有什么区别assert,expect和should什么时候使用什么?
assert.equal(3, '3', '== coerces values to strings');
var foo = 'bar';
expect(foo).to.equal('bar');
foo.should.equal('bar');
Run Code Online (Sandbox Code Playgroud) 如果我们有单元测试文件my-spec.js并使用mocha运行,我有以下问题:
mocha my-spec.js
Run Code Online (Sandbox Code Playgroud)
默认超时为2000 ms.可以使用命令行参数覆盖部分测试:
mocha my-spec.js --timeout 5000
Run Code Online (Sandbox Code Playgroud)
问题是:是否有可能全局更改所有测试的默认超时?即你打电话的时候
mocha my-spec.js
Run Code Online (Sandbox Code Playgroud)
默认超时值不同于2000毫秒提前感谢
我试图弄清楚如何在nodejs中测试内部(即未导出)函数(最好使用mocha或jasmine).我不知道!
假设我有一个这样的模块:
function exported(i) {
return notExported(i) + 1;
}
function notExported(i) {
return i*2;
}
exports.exported = exported;
Run Code Online (Sandbox Code Playgroud)
以下测试(摩卡):
var assert = require('assert'),
test = require('../modules/core/test');
describe('test', function(){
describe('#exported(i)', function(){
it('should return (i*2)+1 for any given i', function(){
assert.equal(3, test.exported(1));
assert.equal(5, test.exported(2));
});
});
});
Run Code Online (Sandbox Code Playgroud)
有没有办法对notExported函数进行单元测试而不实际导出它,因为它不是要暴露的?