Skip to content

Commit 3961ee4

Browse files
committed
move rendering tests from examples/src/try
1 parent 3017682 commit 3961ee4

4 files changed

Lines changed: 137 additions & 4 deletions

File tree

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
language: node_js
22
node_js:
3-
- "0.10"
4-
- "0.12"
53
- "4.0"
64
- "5.0"
5+
- "5"
76
before_install:
87
- npm install -g npm@3
98
env:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ examples: examples/src/*/* dist/schwartzman.js
1818

1919
.PHONY: test
2020
test: dist/schwartzman.js
21-
NODE_ENV=test $(mocha) && make examples
21+
NODE_ENV=test $(mocha)

src/schwartzman.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ module.exports = function(content) {
471471
472472
module.exports = function (props) { return ${result} }
473473
module.exports.raw = ${JSON.stringify(content)}
474-
if (process.env.NODE_ENV === 'test') { module.exports }
474+
if (process && process.env && process.env.NODE_ENV === 'test') { module.exports }
475475
`
476476
}
477477

test/rendering.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,138 @@ describe('rendering', function () {
1818
)
1919
)
2020
})
21+
22+
it('correct scope search: outer', function () {
23+
var tmpl = eval(schwartzman(`
24+
<div>
25+
{{#name}}
26+
<b class=x>
27+
{{name}}
28+
</b>
29+
{{/name}}
30+
{{#wrapper}}@@{{name}}@@{{/wrapper}}
31+
</div>
32+
`))
33+
34+
assert.equal(
35+
'<div><b class="x">Jason</b></div>',
36+
ReactDOMServer.renderToStaticMarkup(
37+
React.createElement(tmpl, {name: 'Jason', wrapper: false})
38+
)
39+
)
40+
})
41+
42+
it('correct scope search: inner', function () {
43+
var tmpl = eval(schwartzman(`
44+
<div>
45+
{{#obj}}
46+
{{#i}}
47+
+++{{i}}+++
48+
{{/i}}
49+
50+
{{^k}}
51+
~~~{{i}}~~~
52+
{{/k}}
53+
---{{k}}---
54+
==={{name}}===
55+
{{/obj}}
56+
</div>
57+
`))
58+
59+
assert.equal(
60+
`<div>+++42+++
61+
~~~42~~~
62+
------
63+
===Jason===
64+
</div>`.replace(/^\s{2,}/gm, ' '),
65+
ReactDOMServer.renderToStaticMarkup(
66+
React.createElement(tmpl, {name: 'Jason', obj: {i: 42}})
67+
).replace(/^\s{2,}/gm, ' ')
68+
)
69+
})
70+
71+
it('comments', function () {
72+
var tmpl = eval(schwartzman(`
73+
<div>
74+
<!--<b></b>-->
75+
<i></i>
76+
<!--<b></b>-->
77+
<i></i>
78+
<!--<b></b>-->
79+
</div>
80+
`))
81+
82+
assert.equal(
83+
`<div><i></i><i></i></div>`,
84+
ReactDOMServer.renderToStaticMarkup(
85+
React.createElement(tmpl, {})
86+
)
87+
)
88+
})
89+
90+
it('arrays', function () {
91+
var tmpl = eval(schwartzman(`
92+
<div>
93+
<ul>
94+
{{#people}}
95+
<li>{{name}}</li>
96+
{{/people}}
97+
</ul>
98+
<span>
99+
{{#people}}la {{/people}}
100+
</span>
101+
{{^people}}<span>no people</span>{{/people}}
102+
{{^animals}}<span>no animals</span>{{/animals}}
103+
</div>
104+
`))
105+
106+
assert.equal(
107+
`<div><ul><li>Alice</li><li>Bob</li></ul><span>la la </span><span>no animals</span></div>`,
108+
ReactDOMServer.renderToStaticMarkup(
109+
React.createElement(tmpl, {people: [
110+
{name: 'Alice'},
111+
{name: 'Bob'},
112+
]})
113+
)
114+
)
115+
})
116+
117+
it('escaping', function () {
118+
var tmpl = eval(schwartzman(`
119+
<div>
120+
<b>{{{ noEscape }}}</b>
121+
<b>{{{ amp }}}</b>
122+
</div>
123+
`))
124+
125+
assert.equal(
126+
`<div><b><i>lol</i></b><b>&amp;</b></div>`,
127+
ReactDOMServer.renderToStaticMarkup(
128+
React.createElement(tmpl, {
129+
noEscape: '<i>lol</i>',
130+
amp: '&amp;',
131+
})
132+
)
133+
)
134+
})
135+
136+
it('attributes', function () {
137+
var tmpl = eval(schwartzman(`
138+
<div>
139+
<b checked>{{{ amp }}}</b>
140+
<div class={{#amp}}lol{{/amp}} />
141+
<div {{#amp}}checked{{/amp}} />
142+
<i style="text-decoration: underline">underlined</i>
143+
</div>
144+
`))
145+
146+
assert.equal(
147+
`<div><b checked="">&amp;</b><div class="lol"></div><div checked=""></div><i style="text-decoration:underline;">underlined</i></div>`,
148+
ReactDOMServer.renderToStaticMarkup(
149+
React.createElement(tmpl, {
150+
amp: '&amp;',
151+
})
152+
)
153+
)
154+
})
21155
})

0 commit comments

Comments
 (0)