remove chai from unit tests

This commit is contained in:
Karsten Hassel
2021-06-08 00:47:15 +02:00
parent 66759a33fa
commit 16bbb42b8d
10 changed files with 66 additions and 79 deletions

View File

@@ -1,16 +1,15 @@
const expect = require("chai").expect;
const deprecated = require("../../../js/deprecated");
describe("Deprecated", function () {
it("should be an object", function () {
expect(deprecated).to.be.an("object");
expect(typeof deprecated).toBe("object");
});
it("should contain configs array with deprecated options as strings", function () {
expect(deprecated.configs).to.be.an("array");
expect(Array.isArray(["deprecated.configs"])).toBe(true);
for (let option of deprecated.configs) {
expect(option).to.be.an("string");
expect(typeof option).toBe("string");
}
expect(deprecated.configs).to.include("kioskmode");
expect(deprecated.configs).toEqual(expect.arrayContaining(["kioskmode"]));
});
});

View File

@@ -1,4 +1,3 @@
const expect = require("chai").expect;
const path = require("path");
const helmet = require("helmet");
const { JSDOM } = require("jsdom");
@@ -82,9 +81,9 @@ describe("Translator", function () {
const { Translator } = dom.window;
setTranslations(Translator);
let translation = Translator.translate({ name: "MMM-Module" }, "Hello");
expect(translation).to.be.equal("Hallo");
expect(translation).toBe("Hallo");
translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}", { username: "fewieden" });
expect(translation).to.be.equal("Hallo fewieden");
expect(translation).toBe("Hallo fewieden");
done();
};
});
@@ -95,9 +94,9 @@ describe("Translator", function () {
const { Translator } = dom.window;
setTranslations(Translator);
let translation = Translator.translate({ name: "MMM-Module" }, "FOO");
expect(translation).to.be.equal("Foo");
expect(translation).toBe("Foo");
translation = Translator.translate({ name: "MMM-Module" }, "BAR {something}", { something: "Lorem Ipsum" });
expect(translation).to.be.equal("Bar Lorem Ipsum");
expect(translation).toBe("Bar Lorem Ipsum");
done();
};
});
@@ -108,7 +107,7 @@ describe("Translator", function () {
const { Translator } = dom.window;
setTranslations(Translator);
const translation = Translator.translate({ name: "MMM-Module" }, "A key");
expect(translation).to.be.equal("A translation");
expect(translation).toBe("A translation");
done();
};
});
@@ -119,7 +118,7 @@ describe("Translator", function () {
const { Translator } = dom.window;
setTranslations(Translator);
const translation = Translator.translate({ name: "MMM-Module" }, "Fallback");
expect(translation).to.be.equal("core fallback");
expect(translation).toBe("core fallback");
done();
};
});
@@ -130,7 +129,7 @@ describe("Translator", function () {
const { Translator } = dom.window;
setTranslations(Translator);
const translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}");
expect(translation).to.be.equal("Hallo {username}");
expect(translation).toBe("Hallo {username}");
done();
};
});
@@ -141,7 +140,7 @@ describe("Translator", function () {
const { Translator } = dom.window;
setTranslations(Translator);
const translation = Translator.translate({ name: "MMM-Module" }, "MISSING");
expect(translation).to.be.equal("MISSING");
expect(translation).toBe("MISSING");
done();
};
});
@@ -163,7 +162,7 @@ describe("Translator", function () {
Translator.load(mmm, file, false, function () {
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
expect(Translator.translations[mmm.name]).to.be.deep.equal(json);
expect(Translator.translations[mmm.name]).toEqual(json);
done();
});
};
@@ -177,7 +176,7 @@ describe("Translator", function () {
Translator.load(mmm, file, true, function () {
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
expect(Translator.translationsFallback[mmm.name]).to.be.deep.equal(json);
expect(Translator.translationsFallback[mmm.name]).toEqual(json);
done();
});
};
@@ -198,8 +197,8 @@ describe("Translator", function () {
};
Translator.load(mmm, file, false, function () {
expect(Translator.translations[mmm.name]).to.be.equal(undefined);
expect(Translator.translationsFallback[mmm.name]).to.be.deep.equal({
expect(Translator.translations[mmm.name]).toBe(undefined);
expect(Translator.translationsFallback[mmm.name]).toEqual({
Hello: "Hallo"
});
done();
@@ -221,8 +220,8 @@ describe("Translator", function () {
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
setTimeout(function () {
expect(Translator.coreTranslations).to.be.deep.equal(en);
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
expect(Translator.coreTranslations).toEqual(en);
expect(Translator.coreTranslationsFallback).toEqual(en);
done();
}, 500);
};
@@ -240,8 +239,8 @@ describe("Translator", function () {
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
setTimeout(function () {
expect(Translator.coreTranslations).to.be.deep.equal({});
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
expect(Translator.coreTranslations).toEqual({});
expect(Translator.coreTranslationsFallback).toEqual(en);
done();
}, 500);
};
@@ -261,7 +260,7 @@ describe("Translator", function () {
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
setTimeout(function () {
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
expect(Translator.coreTranslationsFallback).toEqual(en);
done();
}, 500);
};
@@ -278,7 +277,7 @@ describe("Translator", function () {
Translator.loadCoreTranslations();
setTimeout(function () {
expect(Translator.coreTranslationsFallback).to.be.deep.equal({});
expect(Translator.coreTranslationsFallback).toEqual({});
done();
}, 500);
};

View File

@@ -1,4 +1,3 @@
const expect = require("chai").expect;
const Utils = require("../../../js/utils.js");
const colors = require("colors/safe");
@@ -11,29 +10,29 @@ describe("Utils", function () {
});
it("should have info, warn and error properties", function () {
expect(Utils.colors).to.have.property("info");
expect(Utils.colors).to.have.property("warn");
expect(Utils.colors).to.have.property("error");
expect(Utils.colors).toHaveProperty("info");
expect(Utils.colors).toHaveProperty("warn");
expect(Utils.colors).toHaveProperty("error");
});
it("properties should be functions", function () {
expect(Utils.colors.info).to.be.a("function");
expect(Utils.colors.warn).to.be.a("function");
expect(Utils.colors.error).to.be.a("function");
expect(typeof Utils.colors.info).toBe("function");
expect(typeof Utils.colors.warn).toBe("function");
expect(typeof Utils.colors.error).toBe("function");
});
it("should print colored message in supported consoles", function () {
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");
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");
});
it("should print message in unsupported consoles", function () {
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!");
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!");
});
});
});