1

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?

Community
  • 1
  • 1
HelloWorld
  • 10,529
  • 10
  • 31
  • 50

1 Answers1

3

hopefully you already got your answer, but for people searching, it's because you should

spyOn(Array.prototype, 'map');
borbulon
  • 1,391
  • 1
  • 11
  • 11