Files
node-template-express/public/js-source/test/index.ts
2020-11-19 22:22:14 +01:00

44 lines
1.2 KiB
TypeScript

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 lang="en">
<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);
});
});