Skip to content

Commit

Permalink
Merge pull request #176 from guumo/add-reportinfo
Browse files Browse the repository at this point in the history
Added new method to report console info messages in debug mode (#175)
  • Loading branch information
j3tan authored Jul 13, 2016
2 parents 334b8e7 + 307bac6 commit ba4e8e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,22 @@ Box.Application = (function() {
} else {
application.fire('warning', data);
}
},

/**
* Display console info messages.
* If in development mode, console.info is invoked.
* @param {*} data A message string or arbitrary data
* @returns {void}
*/
reportInfo: function(data) {
if (globalConfig.debug) {
// We grab console via getGlobal() so we can stub it out in tests
var globalConsole = this.getGlobal('console');
if (globalConsole && globalConsole.info) {
globalConsole.info(data);
}
}
}

});
Expand Down
2 changes: 1 addition & 1 deletion lib/test-service-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// function stubs that are automatically included on a TestServiceProvider
var APPLICATION_CONTEXT_STUBS = [
// Shared between Application and Context
'broadcast', 'getGlobalConfig', 'reportError', 'reportWarning',
'broadcast', 'getGlobalConfig', 'reportError', 'reportWarning', 'reportInfo',

// Application (only ones that should be called from a service)
'start', 'stop', 'startAll', 'stopAll', 'isStarted',
Expand Down
16 changes: 16 additions & 0 deletions tests/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,22 @@ describe('Box.Application', function() {

});

describe('reportInfo()', function() {

it('should do a `console.info` when in debug mode', function() {
Box.Application.init({
debug: true
});

sandbox.mock(Box.Application).expects('getGlobal').withArgs('console').returns({
info: sandbox.mock().withArgs('blah')
});

Box.Application.reportInfo('blah');
});

});

});

});

0 comments on commit ba4e8e7

Please sign in to comment.