Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit b933916

Browse files
committed
unit test: handlebars partials can render JSON values
1 parent 865a6b2 commit b933916

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

test/engine_handlebars_tests.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
// set up environment
102102
var patternlab = new fakePatternLab(); // environment
103103
var assembler = new pa();
104-
104+
105105
// do all the normal processing of the pattern
106106
assembler.process_pattern_iterative(pattern1Path, patternlab);
107107
var helloWorldsPattern = assembler.process_pattern_iterative(pattern2Path, patternlab);
@@ -112,6 +112,29 @@
112112
test.equals(helloWorldsPattern.render(), 'Hello world!\n and Hello world!\n\n');
113113
test.done();
114114
},
115+
'handlebars partials can render JSON values': function (test) {
116+
test.expect(1);
117+
118+
// pattern paths
119+
var pattern1Path = path.resolve(
120+
testPatternsPath,
121+
'00-atoms',
122+
'00-global',
123+
'00-helloworld-withdata.hbs'
124+
);
125+
126+
// set up environment
127+
var patternlab = new fakePatternLab(); // environment
128+
var assembler = new pa();
129+
130+
// do all the normal processing of the pattern
131+
var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab);
132+
assembler.process_pattern_recursive(pattern1Path, patternlab);
133+
134+
// test
135+
test.equals(helloWorldWithData.render(), 'Hello world!\nYeah, we got the subtitle from the JSON.\n');
136+
test.done();
137+
},
115138
'find_pattern_partials finds partials': function(test){
116139
testFindPartials(test, [
117140
"{{> molecules-comment-header}}",
@@ -154,7 +177,7 @@
154177
'{{> myPartial name=../name }}'
155178
]);
156179
},
157-
180+
158181
'find_pattern_partials finds handlebars block partials': function(test){
159182
testFindPartials(test, [
160183
'{{#> myPartial }}'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello world!
2+
{{ subtitle }}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"subtitle": "Yeah, we got the subtitle from the JSON."
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h2>Call with default JSON environment:</h2>
2+
This is {{> atoms-helloworld-withdata }}
3+
4+
<h2>Call with passed parameter:</h2>
5+
However, this is {{> atoms-helloworld-withdata otherBlob }}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"subtitle": "from the default JSON.",
3+
"otherBlob": {
4+
"subtitle": "from a totally different blob."
5+
}
6+
}

0 commit comments

Comments
 (0)