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