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,57 @@
import {describe, it} from 'mocha';
import {expect} from 'chai';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import * as fetchMock from 'fetch-mock';
import {getUserName} from '../src/SomeModule';
import {setConfig, UserInfo} from '../src/utils/utils';
describe('frontend:SomeModule', () => {
const CONFIG = {EXTERNAL_BASE_URL: "http://demo.url"};
before(() => {
setConfig(CONFIG);
fetchMock.config.overwriteRoutes = true;
});
it('should return username', async () => {
const tests: [Partial<UserInfo>, string][] = [
[
{name: "John Doe"},
"John Doe",
], [
{name: "John Doe", email: "some.mail@example.com"},
"John Doe",
], [
{name: "", email: "some.mail@example.com"},
"",
],
];
for (const [USER_INFO, RESULT] of tests) {
fetchMock.mock('http://demo.url/api/user', {
status: 200,
body: JSON.stringify(USER_INFO),
});
const name = await getUserName();
expect(name).to.deep.equal(RESULT);
}
});
it('should return default string', async () => {
const RESULT = "No name found!";
const tests: (Partial<UserInfo>|unknown)[] = [
// eslint-disable-next-line no-null/no-null
{name: null},
// eslint-disable-next-line no-null/no-null
null,
{email: "some.mail@example.com"},
{name: undefined},
{},
];
for (const USER_INFO of tests) {
fetchMock.mock('http://demo.url/api/user', {
status: 200,
body: JSON.stringify(USER_INFO),
});
const name = await getUserName();
expect(name).to.deep.equal(RESULT);
}
});
});