相关疑难解决方法(0)

在调用异步函数的mocha测试中如何避免超时错误:超过2000ms的超时

在我的节点应用程序中,我使用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)

mocha.js node.js chai

190
推荐指数
4
解决办法
14万
查看次数

标签 统计

chai ×1

mocha.js ×1

node.js ×1