【问题标题】:Ensure the done() callback is being called in this test (Mocha, Chai, Sinon)确保在此测试中调用了 done() 回调(Mocha、Chai、Sinon)
【发布时间】:2016-02-26 16:25:33
【问题描述】:

查看其他问题,并不能真正找到问题的原因。我正在尝试导入一个模块并使用 mocha 对其进行测试。

import chai, {
    expect
}
from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import System from 'systemjs';
import '../public/config.js';

chai.use(sinonChai);

describe('helperModule', () => {
    let module;

    before(function () {
        return System.import('./public/js/helper.js')
            .then((mod) => module = mod);
    });

    describe('Module loading', function () {
        it('should load', function(){
            expect(module.default).to.not.be.undefined;
        });
    });
});

运行npm test 命令时出现以下错误。

1) helperModule "before all" hook:
     Error: timeout of 2000ms exceeded. Ensure the done() callback is being
 called in this test.

不太确定将完成的回调放在哪里。如果您需要有关我正在使用的任何软件包的任何额外信息,我将与他们一起编辑我的问题。

【问题讨论】:

    标签: javascript mocha.js


    【解决方案1】:

    期望在您的测试完成时调用 done() 回调。一些库会为您隐式执行此操作,您还可以将 done 传递给其他函数,这些函数将在成功时调用它。如果需要手动完成,可以将 done 指定为稍后调用的测试函数的参数。

    describe('Module loading', function () {
        it('should load', function(done){
            expect(module.default).to.not.be.undefined;
            done();
        });
    });
    

    【讨论】:

    • 我现在又遇到了一个错误,我想我只能让它直到它刷新测试。这个有什么想法吗?无法读取未定义评估文件的属性“createElement”:///jspm_packages/npm/jquery@2.1.4/dist/jquery.js
    猜你喜欢
    • 2017-03-12
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 2015-12-01
    • 2018-04-08
    • 1970-01-01
    相关资源
    最近更新 更多