MagicMirror/tests/unit/classes/utils_spec.js

40 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-04-19 08:18:11 +02:00
const expect = require("chai").expect;
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 () {
2018-02-10 12:30:33 +01:00
var colorsEnabled = colors.enabled;
afterEach(function () {
2018-02-10 12:30:33 +01:00
colors.enabled = colorsEnabled;
});
it("should have info, warn and error properties", function () {
2018-02-10 12:30:33 +01:00
expect(Utils.colors).to.have.property("info");
expect(Utils.colors).to.have.property("warn");
expect(Utils.colors).to.have.property("error");
});
it("properties should be functions", function () {
2018-02-10 12:30:33 +01:00
expect(Utils.colors.info).to.be.a("function");
expect(Utils.colors.warn).to.be.a("function");
expect(Utils.colors.error).to.be.a("function");
});
it("should print colored message in supported consoles", function () {
2018-02-10 12:30:33 +01:00
colors.enabled = true;
expect(Utils.colors.info("some informations")).to.be.equal("\u001b[34msome informations\u001b[39m");
expect(Utils.colors.warn("a warning")).to.be.equal("\u001b[33ma warning\u001b[39m");
expect(Utils.colors.error("ERROR!")).to.be.equal("\u001b[31mERROR!\u001b[39m");
});
it("should print message in unsupported consoles", function () {
2018-02-10 12:30:33 +01:00
colors.enabled = false;
expect(Utils.colors.info("some informations")).to.be.equal("some informations");
expect(Utils.colors.warn("a warning")).to.be.equal("a warning");
expect(Utils.colors.error("ERROR!")).to.be.equal("ERROR!");
});
});
});