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
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
describe("Utils", () => {
|
|
|
|
describe("colors", () => {
|
2021-04-08 21:12:56 +02:00
|
|
|
const colorsEnabled = colors.enabled;
|
2018-02-10 12:30:33 +01:00
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
afterEach(() => {
|
2018-02-10 12:30:33 +01:00
|
|
|
colors.enabled = colorsEnabled;
|
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should have info, warn and error properties", () => {
|
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
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("properties should be functions", () => {
|
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
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should print colored message in supported consoles", () => {
|
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
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should print message in unsupported consoles", () => {
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|