Skip to content

Commit 96b16a9

Browse files
committed
Issue angular#2343 Fix
Added $logProvider.debugEnabled method to $logProvider Mock. Added $log.debug method to Mock.
1 parent c9c3f71 commit 96b16a9

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/ngMock/angular-mocks.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,28 @@ angular.mock.$ExceptionHandlerProvider = function() {
293293
*
294294
*/
295295
angular.mock.$LogProvider = function() {
296+
var debug = true;
296297

297298
function concat(array1, array2, index) {
298299
return array1.concat(Array.prototype.slice.call(array2, index));
299300
}
300301

302+
this.debugEnabled = function(flag) {
303+
if (flag) {
304+
debug = flag;
305+
return this;
306+
} else {
307+
return debug;
308+
}
309+
};
301310

302311
this.$get = function () {
303312
var $log = {
304313
log: function() { $log.log.logs.push(concat([], arguments, 0)); },
305314
warn: function() { $log.warn.logs.push(concat([], arguments, 0)); },
306315
info: function() { $log.info.logs.push(concat([], arguments, 0)); },
307-
error: function() { $log.error.logs.push(concat([], arguments, 0)); }
316+
error: function() { $log.error.logs.push(concat([], arguments, 0)); },
317+
debug: function() { $log.debug.logs.push(concat([], arguments, 0)); }
308318
};
309319

310320
/**
@@ -376,6 +386,21 @@ angular.mock.$LogProvider = function() {
376386
* </pre>
377387
*/
378388
$log.error.logs = [];
389+
/**
390+
* @ngdoc property
391+
* @name ngMock.$log#debug.logs
392+
* @propertyOf ngMock.$log
393+
*
394+
* @description
395+
* Array of messages logged using {@link ngMock.$log#debug}.
396+
*
397+
* @example
398+
* <pre>
399+
* $log.debug('Some Error');
400+
* var first = $log.debug.logs.unshift();
401+
* </pre>
402+
*/
403+
$log.debug.logs = []
379404
};
380405

381406
/**
@@ -388,7 +413,7 @@ angular.mock.$LogProvider = function() {
388413
*/
389414
$log.assertEmpty = function() {
390415
var errors = [];
391-
angular.forEach(['error', 'warn', 'info', 'log'], function(logLevel) {
416+
angular.forEach(['error', 'warn', 'info', 'log', 'debug'], function(logLevel) {
392417
angular.forEach($log[logLevel].logs, function(log) {
393418
angular.forEach(log, function (logItem) {
394419
errors.push('MOCK $log (' + logLevel + '): ' + String(logItem) + '\n' + (logItem.stack || ''));

0 commit comments

Comments
 (0)