-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreference.js
203 lines (202 loc) · 5.94 KB
/
reference.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
let suite = {
name: 'Reference',
tests: [
{
description: 'Reference alone should render a text node in a document fragment',
template: '{name}',
context: {name: 'Dorothy'},
expectedHTML: 'Dorothy'
},
{
description: 'Reference before some text',
template: '{name} of Kansas',
context: {name: 'Dorothy'},
expectedHTML: 'Dorothy of Kansas'
},
{
description: 'Reference after some text',
template: 'Helen {name}',
context: {name: 'Hunt'},
expectedHTML: 'Helen Hunt'
},
{
description: 'Reference surrounded by text',
template: 'Ruby {color} slippers',
context: {color: 'red'},
expectedHTML: 'Ruby red slippers'
},
{
description: 'Reference before an element',
template: '{name}<div></div>',
context: {name: 'Dorothy'},
expectedHTML: 'Dorothy<div></div>'
},
{
description: 'Reference after an element',
template: '<div></div>{name}',
context: {name: 'Hunt'},
expectedHTML: '<div></div>Hunt'
},
{
description: 'Reference surrounded by elements',
template: '<span></span>{color}<span></span>',
context: {color: 'red'},
expectedHTML: '<span></span>red<span></span>'
},
{
description: 'Reference in an element',
template: '<div>{name}</div>',
context: {name: 'Dorothy'},
expectedHTML: '<div>Dorothy</div>'
},
{
description: 'Reference in an element with other text',
template: '<div>{name} is a dog</div>',
context: {name: 'Toto'},
expectedHTML: '<div>Toto is a dog</div>'
},
{
description: 'Reference in a nested element without other text',
template: '<div><span>{name}</span></div>',
context: {name: 'Toto'},
expectedHTML: '<div><span>Toto</span></div>'
},
{
description: 'Reference in a nested element with other text',
template: '<div><span>{name} is a dog</span></div>',
context: {name: 'Toto'},
expectedHTML: '<div><span>Toto is a dog</span></div>'
},
{
description: 'Reference in an attribute',
template: '<div class="{name}"></div>',
context: {name: 'Dorothy'},
expectedHTML: '<div class="Dorothy"></div>'
},
{
description: 'Reference in an attribute with other text in the attribute',
template: '<div class="oz {name}"></div>',
context: {name: 'Dorothy'},
expectedHTML: '<div class="oz Dorothy"></div>'
},
{
description: 'Reference with a dot separated path',
template: '{character.firstName}',
context: {character: {firstName: 'Dorothy'}},
expectedHTML: 'Dorothy'
},
{
description: 'Reference with a dot separated path where last step does not exist',
template: 'Hello, {character.firstName}',
context: {character: {}},
expectedHTML: 'Hello, '
},
{
description: 'Reference with a dot separated path where first step does not exist',
template: 'Hello, {character.firstName}',
context: {},
expectedHTML: 'Hello, '
},
{
description: 'Single dot reference',
template: '{.}',
context: 'Dorothy',
expectedHTML: 'Dorothy'
},
{
description: 'Reference is a promise',
template: '<div>{now}</div>',
context: {
now: new Promise((resolve) => {
resolve('and later');
})
},
expectedHTML: '<div>and later</div>'
},
{
description: 'Reference at fragment root is a promise',
template: '{now}',
context: {
now: new Promise((resolve) => {
resolve('and later');
})
},
expectedHTML: 'and later'
},
{
description: 'Reference is a promise that rejects',
template: '<div>{now}</div>',
context: {
now: new Promise((resolve, reject) => {
reject();
})
},
expectedHTML: '<div></div>'
},
{
description: 'Reference in an attribute is a promise',
template: '<div class="{now}"></div>',
context: {
now: new Promise((resolve) => {
resolve('later');
})
},
expectedHTML: '<div class="later"></div>'
},
{
description: 'Reference is a function that returns a string',
template: '<blockquote>The name is {lastName}, {fullName}.</blockquote>',
context: {
fullName: function() {
return this.firstName + ' ' + this.lastName;
},
firstName: 'James',
lastName: 'Bond'
},
expectedHTML: '<blockquote>The name is Bond, James Bond.</blockquote>'
},
{
description: 'Reference is a function that returns a Promise',
template: '<blockquote>The name is {lastName}, {fullName}.</blockquote>',
context: {
fullName: function() {
return new Promise((resolve) => {
resolve(this.firstName + ' ' + this.lastName);
});
},
firstName: 'James',
lastName: 'Bond'
},
expectedHTML: '<blockquote>The name is Bond, James Bond.</blockquote>'
},
{
description: 'Reference with dots, where first part of path is a function returning an object',
template: '<blockquote>The name is {name.lastName}.</blockquote>',
context: {
name: function() {
return {
firstName: 'James',
lastName: 'Bond'
};
}
},
expectedHTML: '<blockquote>The name is Bond.</blockquote>'
},
{
description: 'Reference with dots, where first part of path is a function returning a Promise',
template: '<blockquote>The name is {name.lastName}.</blockquote>',
context: {
name: function() {
return new Promise((resolve) => {
resolve({
firstName: 'James',
lastName: 'Bond'
});
});
}
},
expectedHTML: '<blockquote>The name is Bond.</blockquote>'
}
]
};
export default suite;