【发布时间】:2015-06-10 23:45:18
【问题描述】:
这很奇怪。使用 testem 运行器和 jasmine2 并执行以下规范(尽管它正确地标记了没有期望):
describe('Spying on array.prototype methods', function(){
it('should work this way', function(){
spyOn( Array.prototype, 'push' ).and.callThrough();
// expect(1).toBe(1);
});
});
但是,添加一个expect(任何expect!),它会导致堆栈溢出,并在testem 控制台中显示以下消息:RangeError: Maximum call stack size exceeded. at http://localhost:7357/testem/jasmine2.js, line 980 html 报告页面达到规范,然后挂起没有显示任何实际结果。
最终我想做这样的事情:
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();
});
});
提前感谢任何能够阐明这种奇怪现象的人。我不能监视原生原型方法吗?
【问题讨论】:
标签: javascript jasmine prototype spy testem