diff --git a/tests/e2e/mock-console.js b/tests/e2e/mock-console.js index 2d6751cd..8cc246f8 100644 --- a/tests/e2e/mock-console.js +++ b/tests/e2e/mock-console.js @@ -1,9 +1,14 @@ -global.console = { - log: console.log, - dir: console.dir, - // error: jest.fn(), - error: console.error, - warn: console.warn, - info: console.info, - debug: console.debug +function myError(err) { + //console.dir(err); + if (err.includes("ECONNREFUSED")) { jest.fn() } else { console.dir(err) }; +}; + +global.console = { + log: jest.fn(), + dir: console.dir, + error: myError, +// error: console.error, + warn: console.warn, + info: jest.fn(), + debug: console.debug }; diff --git a/tests/e2e/modules.js b/tests/e2e/modules.js index e4856a52..227fd98f 100644 --- a/tests/e2e/modules.js +++ b/tests/e2e/modules.js @@ -1,37 +1,45 @@ const jsdom = require("jsdom"); -const fetch = require("node-fetch"); +// const fetch = require("node-fetch"); const helpers = require("./global-setup"); let app = null; -describe("test headers", function () { - beforeAll(function () { - // todo: require is not defined ... - // jest.mock("logger"); - app = helpers.startApplication("tests/configs/modules/display.js"); - // app = helpers.startApplication("config/config.js"); - }); - afterAll(function () { - helpers.stopApplication(app); - }); +describe("Display of modules", function () { + beforeAll(function () { + // todo: require is not defined ... + // jest.mock("logger"); + app = helpers.startApplication("tests/configs/modules/display.js"); + // app = helpers.startApplication("config/config.js"); + }); + afterAll(function () { + helpers.stopApplication(app); + }); - it("test", function (done) { - jsdom.JSDOM.fromURL("http://localhost:8080", { resources: "usable", runScripts: "dangerously" }).then((dom) => { - // console.log(dom.serialize()); - dom.window.onload = function () { - const doc = dom.window.document; - console.log(doc.querySelector("title").textContent); - const children = doc.body.getElementsByTagName("*"); - for (var i = 0, length = children.length; i < length; i++) { - child = children[i]; - if (child.id !== "") console.dir(child.id); - } - console.log(doc.querySelector("#module_0_helloworld .module-header").textContent); - // result ist leider lowercase wegen fehlendem css, siehe https://stackoverflow.com/questions/10318330/how-do-you-add-stylesheets-to-jsdom - // const elem = doc.getElementById("module_0_helloworld"); - // console.dir(elem); - done(); - }; - }); - // done(); - }); + it("should show the test header", function (done) { + jsdom.JSDOM.fromURL("http://localhost:8080", { resources: "usable", runScripts: "dangerously" }).then((dom) => { + // console.log(dom.serialize()); + dom.window.onload = function () { + const doc = dom.window.document; + let elem = doc.querySelector("title"); + expect(elem).not.toBe(null); + expect(elem.textContent).toBe("MagicMirror²"); +/* + const children = doc.body.getElementsByTagName("*"); + for (var i = 0, length = children.length; i < length; i++) { + child = children[i]; + if (child.id !== "") console.dir(child.id); + } +*/ + elem = doc.querySelector("#module_0_helloworld .module-header"); + expect(elem).not.toBe(null); + expect(elem.textContent).toBe("test_header"); + //result ist leider lowercase wegen fehlendem css, siehe https://stackoverflow.com/questions/10318330/how-do-you-add-stylesheets-to-jsdom + elem = doc.querySelector("#module_1_helloworld .module-header"); + expect(elem).not.toBe(null); + expect(elem.textContent).toBe("undefined"); + + //dom.window.close(); + done(); + }; + }); + }); });