Reputation: 11247
I am writing a test to see if Array.prototype.map
was called. I thought this would work since Array.prototype.map is located on the global window object:
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);
});
I receive the error Array.prototype.map does not exist
. When I create my own custom global functions, this method works fine. Based on this other post It appears any global functions can be spied on using the syntax I am using above. If I create my own functions, this syntax works. Any ideas on why Array.prototype.map
is returning undefined?
Upvotes: 1
Views: 1420
Reputation: 1411
hopefully you already got your answer, but for people searching, it's because you should
spyOn(Array.prototype, 'map');
Upvotes: 3