angularjs - Webpack构建中的sinon模拟超时错误- 'undefined'不是对象(评估 'modules[moduleId].call'

标签 angularjs unit-testing mocha.js sinon stubbing

使用webpack构建,并使用sinon模拟超时,我收到此错误。

未定义”不是对象(评估“modules [moduleId] .call

代码如下。

var sinon = require('sinon');

describe('sinon stubbing', function () {
var clock;

before(function () {
    clock = sinon.useFakeTimers();
});

it('should wait for timeout and test', function (done) {
    //code with window.timeout testing 
    clock.tick(1000);
    done();
});

after(function () {
    clock.restore();
});

});

我用过
  npm install --save-dev mocha chai sinon

安装依赖项。我也尝试过手动将sinon版本添加到package.json,但是没有运气。

最佳答案

问题出在我的package.json上。
我需要像这样指定sinon依赖性。

  "sinon": "git+https://github.com/sinonjs/sinon.git"

已报告此问题here

关于angularjs - Webpack构建中的sinon模拟超时错误- 'undefined'不是对象(评估 'modules[moduleId].call',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34869017/

相关文章:

javascript - 与 Mocha watch 一起使用时,Sinon stub 有奇怪的行为

javascript - Jest(或 Mocha)如何在无需导入的情况下工作?

javascript - Angular Jasmine SpyOn $resource 处理错误

javascript - 将值从指令传递到 Controller

python - 没有 errbacks 的 Twisted Deferred 错误如何通过试验进行测试?

java - 如何使用 PowerMock 在公共(public)方法内提供对象来访问其中的另一个方法?

c# - 测试 Entity Framework 查找方法

node.js - 配置 Mocha 以持续运行测试失败

javascript - 是否有任何用于构建像 johnpapa/angular-styleguide 这样的 ionic 应用程序的样式指南

javascript - 返回 AngularJS 中两个数组值之间的匹配