【发布时间】:2015-05-02 04:17:16
【问题描述】:
我正在编写一个测试以查看是否调用了 Array.prototype.map。我认为这会起作用,因为 Array.prototype.map 位于全局窗口对象上:
it("does not use Array.prototype.map", function(){
spyOn(window, "Array.prototype.map")
fn([2,2,3]);
expect(Array.prototype.map.calls.count()).toEqual(0);
});
我收到错误Array.prototype.map does not exist。当我创建自己的自定义全局函数时,此方法可以正常工作。 Based on this other post 使用我上面使用的语法似乎可以监视任何全局函数。如果我创建自己的函数,则此语法有效。关于为什么 Array.prototype.map 返回未定义的任何想法?
【问题讨论】:
标签: javascript jasmine