Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new method to report console info messages in debug mode (#175) #176

Merged
merged 2 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});

});

});

});