-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtemplate-string.test.js
46 lines (40 loc) · 1.02 KB
/
template-string.test.js
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
import { compile } from './template-string';
describe('template string', () => {
it('template is empty', () => {
const template = `
<p><%= data.price %> 元</p>
`;
const result = compile(template, null);
expect(result).toBe(template);
});
it('compile a paragraph', () => {
const template = `
<p><%= data.price %> 元</p>
`;
const data = {
price: 10.1,
};
const expectResult = '<p>10.1元</p>';
const result = compile(template, data);
expect(result.replace(/\s/g, '')).toBe(expectResult);
});
it('compile a list', () => {
const template = `
<ul>
<% for(let i=0; i < data.size.length; i++) { %>
<li><%= data.size[i] %></li>
<% } %>
</ul>
`;
const data = {
size: [ 'X', 'XL', 'XLL' ],
};
const expectResult = '<ul>'
+ '<li>X</li>'
+ '<li>XL</li>'
+ '<li>XLL</li>'
+'</ul>';
const result = compile(template, data);
expect(result.replace(/\s/g, '')).toBe(expectResult);
});
});