【发布时间】:2013-06-20 22:12:17
【问题描述】:
我正在尝试使用 sinon.js 来监视 window.document。我要做的是:
var document = {
getElementById = function() {}
}
sinon.spy(document, "getElementById").withArgs("foo").returnValues = ["bar"];
我对这次通话的期望是: 当使用参数“foo”调用 document.getElementById 时,该函数必须返回“bar”。我的错误是什么?
如果我像这样自己定义 getElementById,我会得到预期的结果:
document.getElementById = function(param) {
if (param === "foo") return "bar";
}
【问题讨论】:
标签: javascript testing sinon spy