当在Nodeunit中使用Sandbox时,伊斯坦布尔的代码覆盖错误

我已经使用nodeunit编写了一堆testing来testing我的代码。 在这样做的时候,我想模拟被测代码所需的模块。 而不是改变代码,使其更容易与嘲笑testing,控制反转,当不需要,我改用了nodeunits沙箱function。

var nodeunit = require("nodeunit"); export.MyTest = { test1(test) { var fakeGlobals = { require: function(filename) { if (filename == "CoolUtil.js") { return { doit: function wasCool() { return true; } }; } else { return require(filename); } } }; var testSubject = nodeunit.utils.sandbox("ModuleUnderTest.js", fakeGlobals); test.equals(42, testSubject.doSomethingCoolUsingCoolUtil(), "Worked"); test.done(); } } 

伊斯坦布尔给了我错误的报道数字。 我尝试使用标志–post-require-hook,据说与RequireJS一起使用,我很好切换到但尚未学习。

testing/ node_modules / .bin /伊斯坦布尔封面 – v – 挂机运行在上下文 – 根testing/ node_modules / .bin / nodeunit – –reporter junit –output目标/结果/ unit_teststesting

有没有人在nodeunit,istanbul和nodeunit中使用沙盒function成功?