-
Notifications
You must be signed in to change notification settings - Fork 2
/
server-templates-tests.js
54 lines (43 loc) · 1.54 KB
/
server-templates-tests.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
// Import Tinytest from the tinytest Meteor package.
import { Tinytest } from "meteor/tinytest";
// Import and rename a variable exported by server-templates.js.
import { ServerTemplate } from "meteor/felixble:server-templates";
Tinytest.add('server-templates - compile and render template strings', function (test) {
let date = new Date();
let content = "Hallo {{name}}, time: {{date}}";
let data = {
name: "4Minitz",
date: function() { return date }
};
let result = ServerTemplate.render(content, data);
let expected = "Hallo " + data.name + ", time: " + date;
test.equal(result, expected);
});
Tinytest.add('server-templates - compile and render template strings with helpers', function (test) {
let content = "Hallo {{name}}, sum: {{calcSum}}";
let data = {
name: "4Minitz",
value1: 3,
value2: 5
};
let helpers = {
calcSum: function() {
return this.value1 + this.value2;
}
};
let result = ServerTemplate.render(content, data, helpers);
let expected = "Hallo " + data.name + ", sum: " + 8;
test.equal(result, expected);
});
Tinytest.add('server-templates - loops', function (test) {
const content = "{{#each fruits}}{{id}}: {{name}}/n{{/each}}";
const expected = "0: apple/n1: banana/n2: cherry/n";
const data = {
fruits: [
{id: 0, name: "apple"},
{id: 1, name: "banana"},
{id: 2, name: "cherry"}]
};
const result = ServerTemplate.render(content, data);
test.equal(result, expected);
});