在默认沙箱上使用任何沙箱方法时, restore()
不会正确恢复模拟或间谍。 Sinon v5.0.2 上的最小重现案例:
const sinon = require('sinon');
const myApi = {
someMethod() {
console.log('test method!');
}
};
sinon.stub(myApi, 'someMethod');
sinon.restore();
sinon.stub(myApi, 'someMethod');
// TypeError: Attempted to wrap someMethod which is already wrapped
看来,在调用extend
的lib/sinon.js
,未沙盒stub/spy/etc.
从出口apiMethods
结束了阴影沙箱方法等restore()
什么都不做。 lib/sinon.js
的Sandbox API 文档和来源似乎表明这是预期用途。
我只测试了stub
和spy
,但我希望任何其他隐藏的方法也不能按预期工作。
我通过 Karma/Chromedriver 在 Node v8.9.4 和 Chrome 66.0.3359.117 上运行了这些测试,尽管这个问题似乎与环境无关。
最有用的评论
有了良好的错误报告,大多数错误都很容易解决