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

sinon mocking timeouts in a webpack build gets error - 'undefined' is not an object (evaluating 'modules[moduleId].call'

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

undefined' 不是对象(评估 '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