3 function consoleLogIsCalledBy(log, methodName) {
\r
4 it(methodName + " calls console.log", function() {
\r
5 log.setLevel(log.levels.TRACE);
\r
6 log[methodName]("Log message for call to " + methodName);
\r
7 expect(console.log.calls.length).toEqual(1);
\r
11 function mockConsole() {
\r
12 return {"log" : jasmine.createSpy("console.log")};
\r
15 define(['../lib/loglevel'], function(log) {
\r
16 var originalConsole = window.console;
\r
18 describe("Fallback functionality:", function() {
\r
19 describe("with no console present", function() {
\r
20 beforeEach(function() {
\r
21 window.console = undefined;
\r
24 afterEach(function() {
\r
25 window.console = originalConsole;
\r
28 it("silent method calls are allowed", function() {
\r
29 var result = log.setLevel(log.levels.SILENT);
\r
32 expect(result).toBeUndefined();
\r
35 it("setting an active level gently returns an error string", function() {
\r
36 var result = log.setLevel(log.levels.TRACE);
\r
37 expect(result).toEqual("No console available for logging");
\r
40 it("active method calls are allowed, once the active setLevel fails", function() {
\r
41 log.setLevel(log.levels.TRACE);
\r
45 describe("if a console later appears", function () {
\r
46 it("logging is re-enabled and works correctly when next used", function () {
\r
47 log.setLevel(log.levels.WARN);
\r
49 window.console = mockConsole();
\r
52 expect(window.console.log).toHaveBeenCalled();
\r
55 it("logging is re-enabled but does nothing when used at a blocked level", function () {
\r
56 log.setLevel(log.levels.WARN);
\r
58 window.console = mockConsole();
\r
61 expect(window.console.log).not.toHaveBeenCalled();
\r
64 it("changing level works correctly from that point", function () {
\r
65 window.console = mockConsole();
\r
66 var result = log.setLevel(log.levels.WARN);
\r
68 expect(result).toBeUndefined();
\r
73 describe("with a console that only supports console.log", function() {
\r
74 beforeEach(function() {
\r
75 window.console = mockConsole();
\r
78 afterEach(function() {
\r
79 window.console = originalConsole;
\r
82 it("log can be set to silent", function() {
\r
83 log.setLevel(log.levels.SILENT);
\r
86 it("log can be set to an active level", function() {
\r
87 log.setLevel(log.levels.ERROR);
\r
90 consoleLogIsCalledBy(log, "trace");
\r
91 consoleLogIsCalledBy(log, "debug");
\r
92 consoleLogIsCalledBy(log, "info");
\r
93 consoleLogIsCalledBy(log, "warn");
\r
94 consoleLogIsCalledBy(log, "trace");
\r