diff --git a/tests/unit/classes/deprecated_spec.js b/tests/unit/classes/deprecated_spec.js index f31354c1..9dc3d64a 100644 --- a/tests/unit/classes/deprecated_spec.js +++ b/tests/unit/classes/deprecated_spec.js @@ -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"])); }); }); diff --git a/tests/unit/classes/translator_spec.js b/tests/unit/classes/translator_spec.js index 297a0446..df1934fe 100644 --- a/tests/unit/classes/translator_spec.js +++ b/tests/unit/classes/translator_spec.js @@ -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); }; diff --git a/tests/unit/classes/utils_spec.js b/tests/unit/classes/utils_spec.js index d41411d9..510c29c4 100644 --- a/tests/unit/classes/utils_spec.js +++ b/tests/unit/classes/utils_spec.js @@ -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!"); }); }); }); diff --git a/tests/unit/functions/calendar_spec.js b/tests/unit/functions/calendar_spec.js index 997c609c..073bdcd0 100644 --- a/tests/unit/functions/calendar_spec.js +++ b/tests/unit/functions/calendar_spec.js @@ -1,5 +1,3 @@ -const expect = require("chai").expect; - global.moment = require("moment"); describe("Functions into modules/default/calendar/calendar.js", function () { @@ -26,63 +24,63 @@ describe("Functions into modules/default/calendar/calendar.js", function () { Object.keys(words).forEach((word) => { it(`for '${word}' should return '${words[word]}'`, function () { - expect(Module.definitions.calendar.capFirst(word)).to.equal(words[word]); + expect(Module.definitions.calendar.capFirst(word)).toBe(words[word]); }); }); }); describe("getLocaleSpecification", function () { it("should return a valid moment.LocaleSpecification for a 12-hour format", function () { - expect(Module.definitions.calendar.getLocaleSpecification(12)).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); + expect(Module.definitions.calendar.getLocaleSpecification(12)).toEqual({ longDateFormat: { LT: "h:mm A" } }); }); it("should return a valid moment.LocaleSpecification for a 24-hour format", function () { - expect(Module.definitions.calendar.getLocaleSpecification(24)).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); + expect(Module.definitions.calendar.getLocaleSpecification(24)).toEqual({ longDateFormat: { LT: "HH:mm" } }); }); it("should return the current system locale when called without timeFormat number", function () { - expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: moment.localeData().longDateFormat("LT") } }); + expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: moment.localeData().longDateFormat("LT") } }); }); it("should return a 12-hour longDateFormat when using the 'en' locale", function () { const localeBackup = moment.locale(); moment.locale("en"); - expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); + expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } }); moment.locale(localeBackup); }); it("should return a 12-hour longDateFormat when using the 'au' locale", function () { const localeBackup = moment.locale(); moment.locale("au"); - expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); + expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } }); moment.locale(localeBackup); }); it("should return a 12-hour longDateFormat when using the 'eg' locale", function () { const localeBackup = moment.locale(); moment.locale("eg"); - expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); + expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } }); moment.locale(localeBackup); }); it("should return a 24-hour longDateFormat when using the 'nl' locale", function () { const localeBackup = moment.locale(); moment.locale("nl"); - expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); + expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } }); moment.locale(localeBackup); }); it("should return a 24-hour longDateFormat when using the 'fr' locale", function () { const localeBackup = moment.locale(); moment.locale("fr"); - expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); + expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } }); moment.locale(localeBackup); }); it("should return a 24-hour longDateFormat when using the 'uk' locale", function () { const localeBackup = moment.locale(); moment.locale("uk"); - expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); + expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } }); moment.locale(localeBackup); }); }); @@ -97,32 +95,32 @@ describe("Functions into modules/default/calendar/calendar.js", function () { Object.keys(strings).forEach((string) => { it(`for '${string}' should return '${strings[string].return}'`, function () { - expect(Module.definitions.calendar.shorten(string, strings[string].length)).to.equal(strings[string].return); + expect(Module.definitions.calendar.shorten(string, strings[string].length)).toBe(strings[string].return); }); }); it("should return an empty string if shorten is called with a non-string", function () { - expect(Module.definitions.calendar.shorten(100)).to.equal(""); + expect(Module.definitions.calendar.shorten(100)).toBe(""); }); it("should not shorten the string if shorten is called with a non-number maxLength", function () { - expect(Module.definitions.calendar.shorten("This is a test string", "This is not a number")).to.equal("This is a test string"); + expect(Module.definitions.calendar.shorten("This is a test string", "This is not a number")).toBe("This is a test string"); }); it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (with maxLength defined as 20)", function () { - expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", 20, true)).to.equal( + expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", 20, true)).toBe( "This is a
wrapEvent test. Should wrap
the string instead of
shorten it if called with
wrapEvent = true" ); }); it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (without maxLength defined, default 25)", function () { - expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", undefined, true)).to.equal( + expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", undefined, true)).toBe( "This is a wrapEvent
test. Should wrap the string
instead of shorten it if called
with wrapEvent = true" ); }); it("should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", function () { - expect(Module.definitions.calendar.shorten("This is a wrapEvent and maxTitleLines test. Should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", undefined, true, 2)).to.equal( + expect(Module.definitions.calendar.shorten("This is a wrapEvent and maxTitleLines test. Should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", undefined, true, 2)).toBe( "This is a wrapEvent and
maxTitleLines test. Should wrap and …" ); }); diff --git a/tests/unit/functions/cmp_versions_spec.js b/tests/unit/functions/cmp_versions_spec.js index a9f1bd23..65dbcd92 100644 --- a/tests/unit/functions/cmp_versions_spec.js +++ b/tests/unit/functions/cmp_versions_spec.js @@ -1,4 +1,3 @@ -const expect = require("chai").expect; const path = require("path"); const { JSDOM } = require("jsdom"); @@ -19,14 +18,14 @@ describe("Test function cmpVersions in js/module.js", function () { }); it("should return -1 when comparing 2.1 to 2.2", function () { - expect(cmp("2.1", "2.2")).to.equal(-1); + expect(cmp("2.1", "2.2")).toBe(-1); }); it("should be return 0 when comparing 2.2 to 2.2", function () { - expect(cmp("2.2", "2.2")).to.equal(0); + expect(cmp("2.2", "2.2")).toBe(0); }); it("should be return 1 when comparing 1.1 to 1.0", function () { - expect(cmp("1.1", "1.0")).to.equal(1); + expect(cmp("1.1", "1.0")).toBe(1); }); }); diff --git a/tests/unit/functions/currentweather_spec.js b/tests/unit/functions/currentweather_spec.js index 8a9e7cb3..534c942f 100644 --- a/tests/unit/functions/currentweather_spec.js +++ b/tests/unit/functions/currentweather_spec.js @@ -1,6 +1,4 @@ /* eslint no-multi-spaces: 0 */ -const expect = require("chai").expect; - describe("Functions module currentweather", function () { // Fake for use by currentweather.js Module = {}; @@ -35,7 +33,7 @@ describe("Functions module currentweather", function () { values.forEach((value) => { it(`for ${value[0]} should be return ${value[1]}`, function () { - expect(Module.definitions.currentweather.roundValue(value[0])).to.equal(value[1]); + expect(Module.definitions.currentweather.roundValue(value[0])).toBe(value[1]); }); }); }); @@ -60,7 +58,7 @@ describe("Functions module currentweather", function () { values.forEach((value) => { it(`for ${value[0]} should be return ${value[1]}`, function () { - expect(Module.definitions.currentweather.roundValue(value[0])).to.equal(value[1]); + expect(Module.definitions.currentweather.roundValue(value[0])).toBe(value[1]); }); }); }); diff --git a/tests/unit/functions/newsfeed_spec.js b/tests/unit/functions/newsfeed_spec.js index de3a44ad..5ba3c55c 100644 --- a/tests/unit/functions/newsfeed_spec.js +++ b/tests/unit/functions/newsfeed_spec.js @@ -1,5 +1,3 @@ -const expect = require("chai").expect; - describe("Functions into modules/default/newsfeed/newsfeed.js", function () { // Fake for use by newsletter.js Module = {}; diff --git a/tests/unit/functions/weatherforecast_spec.js b/tests/unit/functions/weatherforecast_spec.js index c21b03cc..e489c874 100644 --- a/tests/unit/functions/weatherforecast_spec.js +++ b/tests/unit/functions/weatherforecast_spec.js @@ -1,5 +1,4 @@ /* eslint no-multi-spaces: 0 */ -const expect = require("chai").expect; const moment = require("moment-timezone"); const data = require("../../configs/data/weatherforecast_data.json"); @@ -35,7 +34,7 @@ describe("Functions module weatherforecast", function () { values.forEach((value) => { it(`for ${value[0]} should be return ${value[1]}`, function () { - expect(Module.definitions.weatherforecast.roundValue(value[0])).to.equal(value[1]); + expect(Module.definitions.weatherforecast.roundValue(value[0])).toBe(value[1]); }); }); }); @@ -60,7 +59,7 @@ describe("Functions module weatherforecast", function () { values.forEach((value) => { it(`for ${value[0]} should be return ${value[1]}`, function () { - expect(Module.definitions.weatherforecast.roundValue(value[0])).to.equal(value[1]); + expect(Module.definitions.weatherforecast.roundValue(value[0])).toBe(value[1]); }); }); }); @@ -91,8 +90,8 @@ describe("Functions module weatherforecast", function () { it(`returns correct icons with sunset time`, function () { Module.definitions.weatherforecast.processWeather(data.withSunset, moment); let forecastData = Module.definitions.weatherforecast.forecast; - expect(forecastData.length).to.equal(4); - expect(forecastData[2].icon).to.equal("wi-rain"); + expect(forecastData.length).toBe(4); + expect(forecastData[2].icon).toBe("wi-rain"); }); }); @@ -104,8 +103,8 @@ describe("Functions module weatherforecast", function () { it(`returns correct icons with out sunset time`, function () { Module.definitions.weatherforecast.processWeather(data.withoutSunset, moment); let forecastData = Module.definitions.weatherforecast.forecast; - expect(forecastData.length).to.equal(4); - expect(forecastData[2].icon).to.equal("wi-rain"); + expect(forecastData.length).toBe(4); + expect(forecastData[2].icon).toBe("wi-rain"); }); }); diff --git a/tests/unit/global_vars/defaults_modules_spec.js b/tests/unit/global_vars/defaults_modules_spec.js index 8d783ff5..e3e53d3f 100644 --- a/tests/unit/global_vars/defaults_modules_spec.js +++ b/tests/unit/global_vars/defaults_modules_spec.js @@ -1,6 +1,5 @@ const fs = require("fs"); const path = require("path"); -const expect = require("chai").expect; const vm = require("vm"); const basedir = path.join(__dirname, "../../.."); @@ -41,7 +40,7 @@ describe("Default modules set in modules/default/defaultmodules.js", function () for (const defaultModule of expectedDefaultModules) { it(`contains a folder for modules/default/${defaultModule}"`, function () { - expect(fs.existsSync(path.join(sandbox.global.root_path, "modules/default", defaultModule))).to.equal(true); + expect(fs.existsSync(path.join(sandbox.global.root_path, "modules/default", defaultModule))).toBe(true); }); } }); diff --git a/tests/unit/global_vars/root_path_spec.js b/tests/unit/global_vars/root_path_spec.js index efe6f792..386ae389 100644 --- a/tests/unit/global_vars/root_path_spec.js +++ b/tests/unit/global_vars/root_path_spec.js @@ -1,6 +1,5 @@ const fs = require("fs"); const path = require("path"); -const expect = require("chai").expect; const vm = require("vm"); beforeAll(function () { @@ -45,20 +44,20 @@ describe("'global.root_path' set in js/app.js", function () { expectedSubPaths.forEach((subpath) => { it(`contains a file/folder "${subpath}"`, function () { - expect(fs.existsSync(path.join(sandbox.global.root_path, subpath))).to.equal(true); + expect(fs.existsSync(path.join(sandbox.global.root_path, subpath))).toBe(true); }); }); it("should not modify global.root_path for testing", function () { - expect(global.root_path).to.equal(undefined); + expect(global.root_path).toBe(undefined); }); it("should not modify global.version for testing", function () { - expect(global.version).to.equal(undefined); + expect(global.version).toBe(undefined); }); it("should expect the global.version equals package.json file", function () { const versionPackage = JSON.parse(fs.readFileSync("package.json", "utf8")).version; - expect(sandbox.global.version).to.equal(versionPackage); + expect(sandbox.global.version).toBe(versionPackage); }); });