summaryrefslogtreecommitdiff
path: root/includes/external/matrix/node_modules/loglevel/test/default-level-test.js
blob: 329c9ddd26a74f5689973316e1ff55576643036f (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"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();
            });
        });

        describe("log.resetLevel() resets the log", function() {
            it("to warn if no explicit default is set", function(log) {
                log.setLevel("debug");
                log.resetLevel();

                expect(log).toBeAtLevel("warn");
            });

            it("to info if default is set to info", function(log) {
                log.setDefaultLevel("info");
                log.setLevel("debug");
                log.resetLevel();

                expect(log).toBeAtLevel("info");
            });
        });
    });
});