这很奇怪.使用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);
});
});
Run Code Online (Sandbox Code Playgroud)
但是,添加一个expect(任何expect!),它会导致堆栈溢出,并在testem控制台中显示以下消息:RangeError: Maximum call stack size exceeded. at http://localhost:7357/testem/jasmine2.js, line 980html报告页面符合规范,然后挂起而不显示任何实际结果.
最终我想做这样的事情:
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();
});
});
Run Code Online (Sandbox Code Playgroud)
提前感谢能够揭示这种奇怪之处的人.我可以不监视原生原型方法吗?