CommunitySolidServer/test/unit/util/templates/EjsTemplateEngine.test.ts
Jasper Vaneessen 2814e72b34
feat: Respect root path for static assets and HTML links
* feat: rootpath for static assets and links1

* fix: static asset handler respects root path

* fix: use rootPath for links

* tests: fix the tests after adding consuctor params

* feat: change matchregex instead of stored URLs

* feat: baseUrl for handlebar engine and templates

* feat: full baseUrl passed to templates

* test: fix integration tests + templates

* chore: implement requested changes

* docs: Describe TemplateEngine interface changes

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>
2022-05-24 10:20:41 +02:00

25 lines
987 B
TypeScript

import { EjsTemplateEngine } from '../../../../src/util/templates/EjsTemplateEngine';
jest.mock('../../../../src/util/templates/TemplateEngine', (): any => ({
getTemplateFilePath: jest.fn((): string => `filename`),
readTemplate: jest.fn(async({ templateString }): Promise<string> => `${templateString}: <%= detail %>`),
}));
describe('A EjsTemplateEngine', (): void => {
const defaultTemplate = { templateString: 'xyz' };
const contents = { detail: 'a&b' };
let templateEngine: EjsTemplateEngine;
beforeEach((): void => {
templateEngine = new EjsTemplateEngine('http://localhost:3000', defaultTemplate);
});
it('uses the default template when no template was passed.', async(): Promise<void> => {
await expect(templateEngine.render(contents)).resolves.toBe('xyz: a&amp;b');
});
it('uses the passed template.', async(): Promise<void> => {
await expect(templateEngine.render(contents, { templateString: 'my' })).resolves.toBe('my: a&amp;b');
});
});