-
-
Notifications
You must be signed in to change notification settings - Fork 535
/
Copy pathregisterHandlebarTemplates.spec.ts
74 lines (64 loc) · 2.81 KB
/
registerHandlebarTemplates.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Handlebars from 'handlebars/runtime';
import { HttpClient } from '../HttpClient';
import * as preCompiler from './preCompileTemplate';
import { registerHandlebarTemplates } from './registerHandlebarTemplates';
jest.mock('handlebars/runtime', () => ({
template: jest.fn((file: string) => file),
registerPartial: jest.fn((file: string) => file),
registerHelper: jest.fn((file: string) => file),
}));
jest.mock('./preCompileTemplate', () => ({
preCompileTemplate: jest.fn((file: string) => file),
}));
describe('registerHandlebarTemplates', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should register handlebar templates', () => {
registerHandlebarTemplates({
httpClient: HttpClient.FETCH,
useOptions: false,
useUnionTypes: false,
});
expect(Handlebars.template).toHaveBeenCalled();
expect(Handlebars.registerPartial).toHaveBeenCalled();
expect(preCompiler.preCompileTemplate).toHaveBeenCalled();
});
it('should return default templates', () => {
const templates = registerHandlebarTemplates({
httpClient: HttpClient.FETCH,
useOptions: false,
useUnionTypes: false,
});
expect(templates.index).toHaveProperty('compiler');
expect(templates.exports.model).toHaveProperty('compiler');
expect(templates.exports.schema).toHaveProperty('compiler');
expect(templates.exports.service).toHaveProperty('compiler');
expect(templates.core.settings).toHaveProperty('compiler');
expect(templates.core.apiError).toHaveProperty('compiler');
expect(templates.core.apiRequestOptions).toHaveProperty('compiler');
expect(templates.core.apiResult).toHaveProperty('compiler');
expect(templates.core.request).toHaveProperty('compiler');
});
it('should allow template overrides', () => {
const templates = registerHandlebarTemplates({
httpClient: HttpClient.FETCH,
useOptions: false,
useUnionTypes: false,
templateOverrides: {
index: 'override',
exportService: 'override',
settings: 'override',
},
});
expect(templates.index).toBe('override');
expect(templates.exports.model).toHaveProperty('compiler');
expect(templates.exports.schema).toHaveProperty('compiler');
expect(templates.exports.service).toBe('override');
expect(templates.core.settings).toBe('override');
expect(templates.core.apiError).toHaveProperty('compiler');
expect(templates.core.apiRequestOptions).toHaveProperty('compiler');
expect(templates.core.apiResult).toHaveProperty('compiler');
expect(templates.core.request).toHaveProperty('compiler');
});
});