MagicMirror/tests/unit/classes/utils_spec.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-04-19 08:18:11 +02:00
const Utils = require("../../../js/utils.js");
const colors = require("colors/safe");
2018-02-10 12:30:33 +01:00
describe("Utils", function () {
describe("colors", function () {
2021-04-08 21:12:56 +02:00
const colorsEnabled = colors.enabled;
2018-02-10 12:30:33 +01:00
afterEach(function () {
2018-02-10 12:30:33 +01:00
colors.enabled = colorsEnabled;
});
it("should have info, warn and error properties", function () {
2021-06-08 00:47:15 +02:00
expect(Utils.colors).toHaveProperty("info");
expect(Utils.colors).toHaveProperty("warn");
expect(Utils.colors).toHaveProperty("error");
2018-02-10 12:30:33 +01:00
});
it("properties should be functions", function () {
2021-06-08 00:47:15 +02:00
expect(typeof Utils.colors.info).toBe("function");
expect(typeof Utils.colors.warn).toBe("function");
expect(typeof Utils.colors.error).toBe("function");
2018-02-10 12:30:33 +01:00
});
it("should print colored message in supported consoles", function () {
2018-02-10 12:30:33 +01:00
colors.enabled = true;
2021-06-08 00:47:15 +02:00
expect(Utils.colors.info("some informations")).toBe("\u001b[34msome informations\u001b[39m");
expect(Utils.colors.warn("a warning")).toBe("\u001b[33ma warning\u001b[39m");
expect(Utils.colors.error("ERROR!")).toBe("\u001b[31mERROR!\u001b[39m");
2018-02-10 12:30:33 +01:00
});
it("should print message in unsupported consoles", function () {
2018-02-10 12:30:33 +01:00
colors.enabled = false;
2021-06-08 00:47:15 +02:00
expect(Utils.colors.info("some informations")).toBe("some informations");
expect(Utils.colors.warn("a warning")).toBe("a warning");
expect(Utils.colors.error("ERROR!")).toBe("ERROR!");
2018-02-10 12:30:33 +01:00
});
});
});