Added frontend tests

This commit is contained in:
Sebastian Seedorf
2020-11-17 00:06:10 +01:00
parent 37c34f99ac
commit b79c2f96cd
16 changed files with 2712 additions and 84 deletions

View File

@@ -0,0 +1,43 @@
import {describe, it} from 'mocha';
import {expect} from 'chai';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {JSDOM} from 'jsdom';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import * as rewire from 'rewire';
describe("frontend:index", () => {
const updateUserName = rewire("../src/index").__get__("updateUserName") as (name: string) => void;
beforeEach(() => {
const dom = new JSDOM(
`
<html>
<body>
</body>
</html>
`,
{url: 'http://localhost'},
);
// noinspection JSConstantReassignment
global.window = dom.window;
// noinspection JSConstantReassignment
global.document = dom.window.document;
});
it("updateUserName", (done) => {
const NAME = "Patrick Star";
const RESULT = "This user name is fetched with Javascript: Patrick Star";
updateUserName(NAME);
// give the browser a chance to update the DOM
setTimeout(() => {
const span = document.getElementsByTagName("span");
expect(span).to.not.be.null;
expect(span.length).to.be.greaterThan(0);
expect(span[0].innerText).to.deep.equal(RESULT);
done();
}, 5);
});
});