When using rewire and sinon fakeTimer, order matters?

纵然是瞬间 提交于 2019-12-06 06:25:25

rewire prepends a list of var statements in order to import all globals into the local module scope. Thus you are able to change global variables without affecting other modules. The downside is that changes to global properties will now be shadowed by the local variables.

These pseudo-code snippets demonstrate the problem:

Without rewire

// Global scope
var setTimeout = global.setTimeout;

(function () {
    // Module scope. Node.js uses eval() and an IIFE to scope variables.
    ...
})()

With rewire

// Global scope
var setTimeout = global.setTimeout;

(function () {
    // Module scope.
    var setTimeout = global.setTimeout;
    ...
})()

You can solve your issue by rewiring after setting up sinon's fake timers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!