This is pretty odd. Using the testem
runner with jasmine2
and the following spec executes (though it correctly flags that there are no expectations):
describe('Spying on array.prototype methods', function(){
it('should work this way', function(){
spyOn( Array.prototype, 'push' ).and.callThrough();
// expect(1).toBe(1);
});
});
However, add an expect
(any expect
!) and it causes the stack to overflow with the following message in the testem
console: RangeError: Maximum call stack size exceeded. at http://localhost:7357/testem/jasmine2.js, line 980
The html report page gets up to the spec and then hangs without showing any actual results.
Ultimately I'd like to do something like this:
describe('Some structure.method', function(){
it('does not use native push', function(){
spyOn( Array.prototype, 'push' ).and.callThrough();
[].push(1); // actually more like `myStructure.myMethod('test')`
expect( Array.prototype.push ).not.toHaveBeenCalled();
});
});
Thanks in advance to anyone who can shed light on this oddity. Can I not spy on native prototypical methods?