Skip to content

Commit b51655c

Browse files
committed
Tests for pretty option
1 parent 0d5ed34 commit b51655c

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/pretty.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { render, shallowRender } from '../src';
2+
import { h, Component } from 'preact';
3+
import { expect, use } from 'chai';
4+
import { spy, match } from 'sinon';
5+
import sinonChai from 'sinon-chai';
6+
use(sinonChai);
7+
8+
describe('pretty', () => {
9+
let prettyRender = jsx => render(jsx, {}, { pretty:true });
10+
11+
it('should render no whitespace by default', () => {
12+
let rendered = render(
13+
<section>
14+
<a href="/foo">foo</a>
15+
bar
16+
<p>hello</p>
17+
</section>
18+
);
19+
20+
expect(rendered).to.equal(`<section><a href="/foo">foo</a>bar<p>hello</p></section>`);
21+
});
22+
23+
it('should render whitespace when pretty=true', () => {
24+
let rendered = prettyRender(
25+
<section>
26+
<a href="/foo">foo</a>
27+
bar
28+
<p>hello</p>
29+
</section>
30+
);
31+
32+
expect(rendered).to.equal(`<section>\n\t<a href="/foo">foo</a>\n\tbar\n\t<p>hello</p>\n</section>`);
33+
});
34+
35+
it('should not indent for short children', () => {
36+
let fourty = '';
37+
for (let i=40; i--; ) fourty += 'x';
38+
39+
expect(
40+
prettyRender(<a href="/foo">{fourty}</a>),
41+
'<=40 characters'
42+
).to.equal(`<a href="/foo">${fourty}</a>`);
43+
44+
expect(
45+
prettyRender(<a href="/foo">{fourty+'a'}</a>),
46+
'>40 characters'
47+
).to.equal(`<a href="/foo">\n\t${fourty+'a'}\n</a>`);
48+
});
49+
50+
it('should handle self-closing tags', () => {
51+
expect(prettyRender(
52+
<div>
53+
hi
54+
<img src="a.jpg" />
55+
<img src="b.jpg" />
56+
<b>hi</b>
57+
</div>
58+
)).to.equal(`<div>\n\thi\n\t<img src="a.jpg">\n\t<img src="b.jpg">\n\t<b>hi</b>\n</div>`);
59+
});
60+
61+
it('should support empty tags', () => {
62+
expect(prettyRender(
63+
<div>
64+
<span />
65+
</div>
66+
)).to.equal(`<div>\n\t<span></span>\n</div>`);
67+
});
68+
});

0 commit comments

Comments
 (0)