Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable eslint jest/expect-expect and jest/no-done-callback #3272

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"import/extensions": "error",
"import/newline-after-import": "error",
"jest/consistent-test-it": "warn",
"jest/expect-expect": "off",
"jest/no-done-callback": "off",
"jest/expect-expect": "warn",
"jest/no-done-callback": "warn",
"jest/prefer-expect-resolves": "warn",
"jest/prefer-mock-promise-shorthand": "warn",
"jest/prefer-to-be": "warn",
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ _This release is scheduled to be released on 2024-01-01._
- Added updatenotification Updater (for 3rd party modules)
- Added node 21 to the test matrix
- Added transform object to calendar:customEvents
- Added ESLint rules for jest
- Added ESLint rules for jest (including jest/expect-expect and jest/no-done-callback)

### Removed

Expand Down
10 changes: 6 additions & 4 deletions tests/e2e/animateCSS_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("AnimateCSS integration Test", () => {
* move similar tests in function doTest
* @param {string} [animationIn] animation in name of AnimateCSS to test.
* @param {string} [animationOut] animation out name of AnimateCSS to test.
* @returns {boolean} result
*/
const doTest = async (animationIn, animationOut) => {
await helpers.getDocument();
Expand All @@ -42,6 +43,7 @@ describe("AnimateCSS integration Test", () => {
} else {
expect(styles._values["animation-name"]).toBeUndefined();
}
return true;
};

afterEach(async () => {
Expand All @@ -51,28 +53,28 @@ describe("AnimateCSS integration Test", () => {
describe("animateIn and animateOut Test", () => {
it("with flipInX and flipOutX animation", async () => {
await helpers.startApplication(testConfigFile);
await doTest("flipInX", "flipOutX");
await expect(doTest("flipInX", "flipOutX")).resolves.toBe(true);
});
});

describe("use animateOut name for animateIn (vice versa) Test", () => {
it("without animation", async () => {
await helpers.startApplication(testConfigFileInvertedAnimationName);
await doTest();
await expect(doTest()).resolves.toBe(true);
});
});

describe("false Animation name test", () => {
it("without animation", async () => {
await helpers.startApplication(testConfigFileFallbackToDefault);
await doTest();
await expect(doTest()).resolves.toBe(true);
});
});

describe("no Animation defined test", () => {
it("without animation", async () => {
await helpers.startApplication(testConfigByDefault);
await doTest();
await expect(doTest()).resolves.toBe(true);
});
});
});
1 change: 1 addition & 0 deletions tests/e2e/helpers/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ exports.testMatch = async (element, regex) => {
const elem = await this.waitForElement(element);
expect(elem).not.toBeNull();
expect(elem.textContent).toMatch(regex);
return true;
};
1 change: 1 addition & 0 deletions tests/e2e/helpers/weather-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports.getText = async (element, result) => {
.replace(/(\r\n|\n|\r)/gm, "")
.replace(/[ ]+/g, " ")
).toBe(result);
return true;
};

exports.startApp = async (configFileName, additionalMockData) => {
Expand Down
37 changes: 20 additions & 17 deletions tests/e2e/modules/calendar_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe("Calendar module", () => {
* @param {string} element css selector
* @param {string} result expected number
* @param {string} not reverse result
* @returns {boolean} result
*/
const testElementLength = async (element, result, not) => {
const elem = await helpers.waitForAllElements(element);
Expand All @@ -15,12 +16,14 @@ describe("Calendar module", () => {
} else {
expect(elem).toHaveLength(result);
}
return true;
};

const testTextContain = async (element, text) => {
const elem = await helpers.waitForElement(element, "undefinedLoading");
expect(elem).not.toBeNull();
expect(elem.textContent).toContain(text);
return true;
};

afterAll(async () => {
Expand All @@ -34,11 +37,11 @@ describe("Calendar module", () => {
});

it("should show the default maximumEntries of 10", async () => {
await testElementLength(".calendar .event", 10);
await expect(testElementLength(".calendar .event", 10)).resolves.toBe(true);
});

it("should show the default calendar symbol in each event", async () => {
await testElementLength(".calendar .event .fa-calendar-alt", 0, "not");
await expect(testElementLength(".calendar .event .fa-calendar-alt", 0, "not")).resolves.toBe(true);
});
});

Expand All @@ -49,27 +52,27 @@ describe("Calendar module", () => {
});

it("should show the custom maximumEntries of 5", async () => {
await testElementLength(".calendar .event", 5);
await expect(testElementLength(".calendar .event", 5)).resolves.toBe(true);
});

it("should show the custom calendar symbol in four events", async () => {
await testElementLength(".calendar .event .fa-birthday-cake", 4);
await expect(testElementLength(".calendar .event .fa-birthday-cake", 4)).resolves.toBe(true);
});

it("should show a customEvent calendar symbol in one event", async () => {
await testElementLength(".calendar .event .fa-dice", 1);
await expect(testElementLength(".calendar .event .fa-dice", 1)).resolves.toBe(true);
});

it("should show a customEvent calendar eventClass in one event", async () => {
await testElementLength(".calendar .event.undo", 1);
await expect(testElementLength(".calendar .event.undo", 1)).resolves.toBe(true);
});

it("should show two custom icons for repeating events", async () => {
await testElementLength(".calendar .event .fa-undo", 2);
await expect(testElementLength(".calendar .event .fa-undo", 2)).resolves.toBe(true);
});

it("should show two custom icons for day events", async () => {
await testElementLength(".calendar .event .fa-calendar-day", 2);
await expect(testElementLength(".calendar .event .fa-calendar-day", 2)).resolves.toBe(true);
});
});

Expand All @@ -80,7 +83,7 @@ describe("Calendar module", () => {
});

it("should show the recurring birthday event 6 times", async () => {
await testElementLength(".calendar .event", 6);
await expect(testElementLength(".calendar .event", 6)).resolves.toBe(true);
});
});

Expand All @@ -91,7 +94,7 @@ describe("Calendar module", () => {
});

it("should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period", async () => {
await testElementLength(".calendar .event", 51);
await expect(testElementLength(".calendar .event", 51)).resolves.toBe(true);
});
});

Expand All @@ -102,7 +105,7 @@ describe("Calendar module", () => {
});

it("should show multiple events with the same title and start time from different calendars", async () => {
await testElementLength(".calendar .event", 22);
await expect(testElementLength(".calendar .event", 22)).resolves.toBe(true);
});
});

Expand All @@ -118,7 +121,7 @@ describe("Calendar module", () => {
});

it(`should contain text "Mar 25th" in timezone UTC ${-i}`, async () => {
await testTextContain(".calendar", "Mar 25th");
await expect(testTextContain(".calendar", "Mar 25th")).resolves.toBe(true);
});
});
}
Expand All @@ -135,7 +138,7 @@ describe("Calendar module", () => {
});

it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
});
});

Expand All @@ -146,7 +149,7 @@ describe("Calendar module", () => {
});

it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
});
});

Expand All @@ -157,7 +160,7 @@ describe("Calendar module", () => {
});

it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
});
});

Expand All @@ -168,7 +171,7 @@ describe("Calendar module", () => {
});

it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
});
});

Expand All @@ -184,7 +187,7 @@ describe("Calendar module", () => {
});

it("should show Unauthorized error", async () => {
await testTextContain(".calendar", "Error in the calendar module. Authorization failed");
await expect(testTextContain(".calendar", "Error in the calendar module. Authorization failed")).resolves.toBe(true);
});
});
});
12 changes: 6 additions & 6 deletions tests/e2e/modules/clock_es_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ describe("Clock set to spanish language module", () => {

it("shows date with correct format", async () => {
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
await helpers.testMatch(".clock .date", dateRegex);
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
});

it("shows time in 24hr format", async () => {
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
await helpers.testMatch(".clock .time", timeRegex);
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
});
});

Expand All @@ -30,12 +30,12 @@ describe("Clock set to spanish language module", () => {

it("shows date with correct format", async () => {
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
await helpers.testMatch(".clock .date", dateRegex);
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
});

it("shows time in 12hr format", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
await helpers.testMatch(".clock .time", timeRegex);
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
});
});

Expand All @@ -47,7 +47,7 @@ describe("Clock set to spanish language module", () => {

it("shows 12hr time with upper case AM/PM", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
await helpers.testMatch(".clock .time", timeRegex);
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
});
});

Expand All @@ -59,7 +59,7 @@ describe("Clock set to spanish language module", () => {

it("shows week with correct format", async () => {
const weekRegex = /^Semana [0-9]{1,2}$/;
await helpers.testMatch(".clock .week", weekRegex);
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
});
});
});
14 changes: 7 additions & 7 deletions tests/e2e/modules/clock_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ describe("Clock module", () => {

it("should show the date in the correct format", async () => {
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
await helpers.testMatch(".clock .date", dateRegex);
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
});

it("should show the time in 24hr format", async () => {
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
await helpers.testMatch(".clock .time", timeRegex);
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
});
});

Expand All @@ -31,12 +31,12 @@ describe("Clock module", () => {

it("should show the date in the correct format", async () => {
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
await helpers.testMatch(".clock .date", dateRegex);
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
});

it("should show the time in 12hr format", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
await helpers.testMatch(".clock .time", timeRegex);
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
});
});

Expand All @@ -48,7 +48,7 @@ describe("Clock module", () => {

it("should show 12hr time with upper case AM/PM", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
await helpers.testMatch(".clock .time", timeRegex);
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
});
});

Expand All @@ -60,7 +60,7 @@ describe("Clock module", () => {

it("should show 12hr time without seconds am/pm", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
await helpers.testMatch(".clock .time", timeRegex);
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
});
});

Expand Down Expand Up @@ -101,7 +101,7 @@ describe("Clock module", () => {

it("should show the week in the correct format", async () => {
const weekRegex = /^Week [0-9]{1,2}$/;
await helpers.testMatch(".clock .week", weekRegex);
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
});

it("should show the week with the correct number of week of year", async () => {
Expand Down
8 changes: 5 additions & 3 deletions tests/e2e/modules/compliments_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ describe("Compliments module", () => {
/**
* move similar tests in function doTest
* @param {Array} complimentsArray The array of compliments.
* @returns {boolean} result
*/
const doTest = async (complimentsArray) => {
let elem = await helpers.waitForElement(".compliments");
expect(elem).not.toBeNull();
elem = await helpers.waitForElement(".module-content");
expect(elem).not.toBeNull();
expect(complimentsArray).toContain(elem.textContent);
return true;
};

afterAll(async () => {
Expand All @@ -25,7 +27,7 @@ describe("Compliments module", () => {
});

it("shows anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
await doTest(["Anytime here"]);
await expect(doTest(["Anytime here"])).resolves.toBe(true);
});
});

Expand All @@ -36,7 +38,7 @@ describe("Compliments module", () => {
});

it("shows anytime compliments", async () => {
await doTest(["Anytime here"]);
await expect(doTest(["Anytime here"])).resolves.toBe(true);
});
});
});
Expand All @@ -48,7 +50,7 @@ describe("Compliments module", () => {
});

it("should show compliments from a remote file", async () => {
await doTest(["Remote compliment file works!"]);
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
});
});
});
Loading