如何使用Karma单元测试运行程序捕获console.error
How to capture console.error with Karma unit test runner?
Karma将捕获任何写入console.log
的消息,但不会捕获任何写入到console.error
的消息。我知道因果报应在幕后使用log4js。
有什么方法可以配置因果报应来捕获console.error
吗?
因果报应确实捕获了console.error
(请参阅https://github.com/karma-runner/karma/blob/415d0257c23ff7be07e240648bfff0bdefa9b0b6/client/karma.js#L70)
确保您设置了配置client.captureConsole: true
并使用最新的Karma。
您可以捕获本博客文章中描述的console.error
describe('TestSuite', function() {
var oldError = console.error;
beforeEach(function() {
console.error = function(message) {
throw new Error(message);
};
});
return afterEach(function() {
return console.error = oldError;
});
it('should fail', function() {
console.error("Oops!")
});
相关文章:
- Array.length似乎不起作用;console.log则显示其他情况
- 有没有一种方法可以在控制台关闭的情况下让console.log()在IE中记录消息
- jQuery Error adadvisor.net
- console.log以外的Javascript输出函数
- Console.debug在ie10中不工作
- 如果在代码末尾进行求值,jQuery-console.log将提供空数组
- Ajax调用ERror Cross Origin REquest:在rails中自动完成大学列表
- 类型error primeFactors.for不是函数
- 如何使用Karma单元测试运行程序捕获console.error
- Node Defender控制台没有't显示console.error()消息
- Chrome Console Error: chromeHidden.Port.dispatchOnDisconnect
- Casperjs catch console.log and console.error
- running error with console.log(util.format
- 为什么console.error是一个方法而不是函数
- console.log格式化的错误对象不同于error.prototype.toString
- throw Error和console.error的区别是什么?
- 为什么?”error = console.trace)(); '使'堆内存溢出'在Node.js中
- Node.js Express,错误处理只适用于console.error
- console.error引发异常
- Spying on console.error() with Jasmine