0

我尝试存根任何全局函数:(function randomNumber(min, max){/*...*/}window.randomNumber === randomNumber但是当我在测试用例中创建存根sinon.stub(window, 'randomNumber')并模拟结果randomNumber.returns(1);)时它不起作用并调用原始的'randomNumber'(window.randomNumber !== randomNumber),为什么?


[编辑]

我的部分代码:https ://plnkr.co/edit/GAaxA3iN8QehDN7HbOc8?p=preview (有趣的是它在浏览器中,在控制台中运行undefined is not a function (evaluating 'randomNumber.onCall(0)'))和package.json

"chai": "^3.5.0", "karma": "^1.7.0", "karma-mocha": "^1.3.0", "karma-phantomjs-launcher": "^1.0.4", "karma-sinon-chai": "^1.3.1", "mocha": "^3.4.1", "phantomjs-prebuilt": "^2.1.14", "sinon": "^2.2.0", "sinon-chai": "^2.10.0", "sinon-stub-promise": "^4.0.0"

4

0 回答 0