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

Explicitly check whether console is defined to prevent IE7 from choking ... #10

Merged
merged 1 commit into from
Sep 3, 2014
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
2 changes: 1 addition & 1 deletion src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
// Configure and example a Default implementation which writes to the `window.console` (if present).
Logger.useDefaults = function(defaultLevel) {
// Check for the presence of a logger.
if (!console) {
if (typeof console === "undefined") {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/logger.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<!-- Qunit mcgubbins -->
<script type="text/javascript" src="vendor/qunit-1.14.0.js"></script>

<!-- Sinon -->
<script type="text/javascript" src="vendor/sinon-1.10.3.js"></script>

<!-- src -->
<script type="text/javascript" src="../src/logger.js"></script>

Expand Down
25 changes: 24 additions & 1 deletion test-src/loggertests.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,27 @@ test("Logger.setLevel - Modify log filter level of all named loggers", function
named.debug("debug message");

ok(this.calls.length === 1, "Logger.setLevel() sets log filter level for all named loggers");
});
});

test("Logger.useDefaults logs to console", function () {
var logger = this.logger;

var sandbox = sinon.sandbox.create();
sandbox.stub(console, "log");
sandbox.stub(console, "info");
sandbox.stub(console, "warn");
sandbox.stub(console, "error");

logger.useDefaults();
logger.debug("debug message");
logger.info("info message");
logger.warn("warning message");
logger.error("error message");

ok(console.log.calledOnce, "logger.debug calls console.log");
ok(console.info.calledOnce, "logger.info calls console.info");
ok(console.warn.calledOnce, "logger.warn calls console.warn");
ok(console.error.calledOnce, "logger.error calls console.error");

sandbox.restore();
});
Loading