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,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 <br>wrapEvent test. Should wrap <br>the string instead of <br>shorten it if called with <br>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 <br>test. Should wrap the string <br>instead of shorten it if called <br>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 <br>maxTitleLines test. Should wrap and &hellip;"
);
});

View File

@@ -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);
});
});

View File

@@ -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]);
});
});
});

View File

@@ -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 = {};

View File

@@ -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");
});
});