get-current-level-test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. define(['test/test-helpers'], function(testHelpers) {
  3. var describeIf = testHelpers.describeIf;
  4. var it = testHelpers.itWithFreshLog;
  5. var originalConsole = window.console;
  6. describe("Setting default log level tests:", function() {
  7. beforeEach(function() {
  8. window.console = {"log" : jasmine.createSpy("console.log")};
  9. });
  10. afterEach(function() {
  11. window.console = originalConsole;
  12. });
  13. describe("If no level is saved", function() {
  14. it("current level is the default level", function(log) {
  15. log.setDefaultLevel("trace");
  16. expect(log.getLevel()).toBe(log.levels.TRACE);
  17. });
  18. });
  19. describe("If a level is saved", function () {
  20. beforeEach(function () {
  21. testHelpers.setStoredLevel("trace");
  22. });
  23. it("current level is the level which has been saved", function (log) {
  24. log.setDefaultLevel("debug");
  25. expect(log.getLevel()).toBe(log.levels.TRACE);
  26. });
  27. });
  28. describe("If the level is stored incorrectly", function() {
  29. beforeEach(function() {
  30. testHelpers.setLocalStorageStoredLevel("gibberish");
  31. });
  32. it("current level is the default level", function(log) {
  33. log.setDefaultLevel("debug");
  34. expect(log.getLevel()).toBe(log.levels.DEBUG);
  35. });
  36. });
  37. });
  38. });