mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Align EJS engine with Handlebars.
This commit is contained in:
committed by
Joachim Van Herwegen
parent
19624dc729
commit
9628fe98b8
23
test/unit/util/templates/EjsTemplateEngine.test.ts
Normal file
23
test/unit/util/templates/EjsTemplateEngine.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { EjsTemplateEngine } from '../../../../src/util/templates/EjsTemplateEngine';
|
||||
|
||||
jest.mock('../../../../src/util/templates/TemplateEngine', (): any => ({
|
||||
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(defaultTemplate);
|
||||
});
|
||||
|
||||
it('uses the default template when no template was passed.', async(): Promise<void> => {
|
||||
await expect(templateEngine.render(contents)).resolves.toBe('xyz: a&b');
|
||||
});
|
||||
|
||||
it('uses the passed template.', async(): Promise<void> => {
|
||||
await expect(templateEngine.render(contents, { templateString: 'my' })).resolves.toBe('my: a&b');
|
||||
});
|
||||
});
|
||||
@@ -22,15 +22,19 @@ describe('readTemplate', (): void => {
|
||||
await expect(readTemplate()).resolves.toBe('');
|
||||
});
|
||||
|
||||
it('accepts string templates.', async(): Promise<void> => {
|
||||
it('accepts a filename.', async(): Promise<void> => {
|
||||
await expect(readTemplate(templateFile)).resolves.toBe('{{template}}');
|
||||
});
|
||||
|
||||
it('accepts options with a string template.', async(): Promise<void> => {
|
||||
await expect(readTemplate({ templateString: 'abc' })).resolves.toBe('abc');
|
||||
});
|
||||
|
||||
it('accepts a filename.', async(): Promise<void> => {
|
||||
it('accepts options with a filename.', async(): Promise<void> => {
|
||||
await expect(readTemplate({ templateFile })).resolves.toBe('{{template}}');
|
||||
});
|
||||
|
||||
it('accepts a filename and path.', async(): Promise<void> => {
|
||||
it('accepts options with a filename and a path.', async(): Promise<void> => {
|
||||
await expect(readTemplate({ templateFile, templatePath })).resolves.toBe('{{other}}');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user