improve tests (#2923)

use es6 syntax in all tests, split weather tests, remove callbacks
This commit is contained in:
Karsten Hassel
2022-10-04 10:15:24 +02:00
committed by GitHub
parent 7694d6fa86
commit f04d578704
41 changed files with 751 additions and 840 deletions

View File

@@ -1,4 +1,5 @@
const jsdom = require("jsdom");
const corefetch = require("fetch");
exports.startApplication = (configFilename, exec) => {
jest.resetModules();
@@ -21,14 +22,16 @@ exports.stopApplication = async () => {
await new Promise((resolve) => setTimeout(resolve, 100));
};
exports.getDocument = (callback) => {
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
dom.window.name = "jsdom";
dom.window.onload = () => {
global.document = dom.window.document;
callback();
};
exports.getDocument = () => {
return new Promise((resolve) => {
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
dom.window.name = "jsdom";
dom.window.onload = () => {
global.document = dom.window.document;
resolve();
};
});
});
};
@@ -71,3 +74,17 @@ exports.waitForAllElements = (selector) => {
}, 100);
});
};
exports.fetch = (url) => {
return new Promise((resolve) => {
corefetch(url).then((res) => {
resolve(res);
});
});
};
exports.testMatch = async (element, regex) => {
const elem = await this.waitForElement(element);
expect(elem).not.toBe(null);
expect(elem.textContent).toMatch(regex);
};