/
mod.test.ts
56 lines (46 loc) · 1.23 KB
/
mod.test.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
import indent from '.';
test('It correctly drops template indentation', () => {
expect(indent`
Test ${"value"}
`).toBe('Test value\n');
});
test('It works when there is no placeholders', () => {
expect(indent`
Test value
`).toBe('Test value\n');
});
test('It reindent placeholders', () => {
expect(indent`
<test>
${"test\nvalue"}
</test>
`).toBe('<test>\n test\n value\n</test>\n');
});
test('It correctly detect indentation when first line is empty', () => {
expect(indent`
Test
`).toBe('\nTest\n');
});
test('It correctly detect indentation when last line is empty', () => {
expect(indent`
Test
`).toBe('Test\n\n');
});
test('It works when placeholder is not indented', () => {
expect(indent`
Foo
${'Bar'}
`).toBe('Foo\nBar\n');
});
test('Nested indent test', () => {
const list = ['First', 'Second'];
expect(indent`
<test>
${list.map((name) => indent`
<value>
${name}
</value>
`).join('')}
</test>
`).toBe(`<test>\n <value>\n First\n </value>\n <value>\n Second\n </value>\n</test>\n`);
})