1
|
"use strict";
|
2
|
|
3
|
define(['test/test-helpers'], function(testHelpers) {
|
4
|
var describeIf = testHelpers.describeIf;
|
5
|
var it = testHelpers.itWithFreshLog;
|
6
|
|
7
|
var originalConsole = window.console;
|
8
|
|
9
|
describe("Setting default log level tests:", function() {
|
10
|
|
11
|
beforeEach(function() {
|
12
|
window.console = {"log" : jasmine.createSpy("console.log")};
|
13
|
this.addMatchers({
|
14
|
"toBeAtLevel" : testHelpers.toBeAtLevel,
|
15
|
"toBeTheStoredLevel" : testHelpers.toBeTheLevelStoredByLocalStorage
|
16
|
});
|
17
|
|
18
|
testHelpers.clearStoredLevels();
|
19
|
});
|
20
|
|
21
|
afterEach(function() {
|
22
|
window.console = originalConsole;
|
23
|
});
|
24
|
|
25
|
describe("If no level is saved", function() {
|
26
|
it("new level is always set", function(log) {
|
27
|
log.setDefaultLevel("trace");
|
28
|
expect(log).toBeAtLevel("trace");
|
29
|
});
|
30
|
|
31
|
it("level is not persisted", function(log) {
|
32
|
log.setDefaultLevel("debug");
|
33
|
expect("debug").not.toBeTheStoredLevel();
|
34
|
});
|
35
|
});
|
36
|
|
37
|
describe("If a level is saved", function () {
|
38
|
beforeEach(function () {
|
39
|
testHelpers.setStoredLevel("trace");
|
40
|
});
|
41
|
|
42
|
it("saved level is not modified", function (log) {
|
43
|
log.setDefaultLevel("debug");
|
44
|
expect(log).toBeAtLevel("trace");
|
45
|
});
|
46
|
});
|
47
|
|
48
|
describe("If the level is stored incorrectly", function() {
|
49
|
beforeEach(function() {
|
50
|
testHelpers.setLocalStorageStoredLevel("gibberish");
|
51
|
});
|
52
|
|
53
|
it("new level is set", function(log) {
|
54
|
log.setDefaultLevel("debug");
|
55
|
expect(log).toBeAtLevel("debug");
|
56
|
expect("debug").not.toBeTheStoredLevel();
|
57
|
});
|
58
|
});
|
59
|
});
|
60
|
});
|