|
1 |
| -import { default as defaultRender, 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); |
| 1 | +import renderToString, { render, shallowRender } from '../src'; |
| 2 | +import { expect } from 'chai'; |
7 | 3 |
|
8 | 4 | describe('render-to-string', () => {
|
9 |
| - describe('default()', () => { |
10 |
| - it('should be render()', () => { |
11 |
| - expect(defaultRender).to.equal(render); |
| 5 | + describe('exports', () => { |
| 6 | + it('exposes renderToString as default', () => { |
| 7 | + expect(renderToString).to.be.a('function'); |
12 | 8 | });
|
13 |
| - }); |
14 | 9 |
|
15 |
| - describe('render()', () => { |
16 |
| - it('should be a function', () => { |
| 10 | + it('exposes render as a named export', () => { |
17 | 11 | expect(render).to.be.a('function');
|
| 12 | + expect(render).to.equal(renderToString); |
18 | 13 | });
|
19 | 14 |
|
20 |
| - describe('Basic JSX', () => { |
21 |
| - it('should render JSX', () => { |
22 |
| - let rendered = render(<div class="foo">bar</div>), |
23 |
| - expected = `<div class="foo">bar</div>`; |
24 |
| - |
25 |
| - expect(rendered).to.equal(expected); |
26 |
| - }); |
27 |
| - |
28 |
| - it('should omit null and undefined attributes', () => { |
29 |
| - let rendered = render(<div a={null} b={undefined} />), |
30 |
| - expected = `<div></div>`; |
31 |
| - |
32 |
| - expect(rendered).to.equal(expected); |
33 |
| - }); |
34 |
| - |
35 |
| - it('should omit functions', () => { |
36 |
| - let rendered = render(<div a={()=>{}} b={function(){}} />), |
37 |
| - expected = `<div></div>`; |
38 |
| - |
39 |
| - expect(rendered).to.equal(expected); |
40 |
| - }); |
41 |
| - |
42 |
| - it('should encode entities', () => { |
43 |
| - let rendered = render(<div a={'"<>&'}>{'"<>&'}</div>), |
44 |
| - expected = `<div a=""<>&">"<>&</div>`; |
45 |
| - |
46 |
| - expect(rendered).to.equal(expected); |
47 |
| - }); |
48 |
| - }); |
49 |
| - |
50 |
| - describe('Functional Components', () => { |
51 |
| - it('should render functional components', () => { |
52 |
| - let Test = spy( ({ foo, children }) => <div foo={foo}>{ children }</div> ); |
53 |
| - |
54 |
| - let rendered = render(<Test foo="test">content</Test>); |
55 |
| - |
56 |
| - expect(rendered) |
57 |
| - .to.equal(`<div foo="test">content</div>`); |
58 |
| - |
59 |
| - expect(Test) |
60 |
| - .to.have.been.calledOnce |
61 |
| - .and.calledWithExactly( |
62 |
| - match({ |
63 |
| - foo: 'test', |
64 |
| - children: ['content'] |
65 |
| - }) |
66 |
| - ); |
67 |
| - }); |
68 |
| - |
69 |
| - it('should render functional components within JSX', () => { |
70 |
| - let Test = spy( ({ foo, children }) => <div foo={foo}>{ children }</div> ); |
71 |
| - |
72 |
| - let rendered = render( |
73 |
| - <section> |
74 |
| - <Test foo={1}><span>asdf</span></Test> |
75 |
| - </section> |
76 |
| - ); |
77 |
| - |
78 |
| - expect(rendered) |
79 |
| - .to.equal(`<section><div foo="1"><span>asdf</span></div></section>`); |
80 |
| - |
81 |
| - expect(Test) |
82 |
| - .to.have.been.calledOnce |
83 |
| - .and.calledWithExactly( |
84 |
| - match({ |
85 |
| - foo: 1, |
86 |
| - children: [ |
87 |
| - match({ nodeName:'span', children:['asdf'] }) |
88 |
| - ] |
89 |
| - }) |
90 |
| - ); |
91 |
| - }); |
92 |
| - }); |
93 |
| - |
94 |
| - describe('Classical Components', () => { |
95 |
| - it('should render classical components', () => { |
96 |
| - class Test extends Component { |
97 |
| - render({ foo, children }, state) { |
98 |
| - return <div foo={foo}>{ children }</div>; |
99 |
| - } |
100 |
| - } |
101 |
| - |
102 |
| - Test = spy(Test); |
103 |
| - spy(Test.prototype, 'render'); |
104 |
| - |
105 |
| - let rendered = render(<Test foo="test">content</Test>); |
106 |
| - |
107 |
| - const PROPS = { |
108 |
| - foo: 'test', |
109 |
| - children: ['content'] |
110 |
| - }; |
111 |
| - |
112 |
| - expect(rendered) |
113 |
| - .to.equal(`<div foo="test">content</div>`); |
114 |
| - |
115 |
| - expect(Test) |
116 |
| - .to.have.been.calledOnce |
117 |
| - .and.calledWith(match(PROPS)); |
118 |
| - |
119 |
| - expect(Test.prototype.render) |
120 |
| - .to.have.been.calledOnce |
121 |
| - .and.calledWithExactly( |
122 |
| - match(PROPS), |
123 |
| - match({}) // empty state |
124 |
| - ); |
125 |
| - }); |
126 |
| - |
127 |
| - it('should render classical components within JSX', () => { |
128 |
| - class Test extends Component { |
129 |
| - render({ foo, children }, state) { |
130 |
| - return <div foo={foo}>{ children }</div>; |
131 |
| - } |
132 |
| - } |
133 |
| - |
134 |
| - Test = spy(Test); |
135 |
| - spy(Test.prototype, 'render'); |
136 |
| - |
137 |
| - let rendered = render( |
138 |
| - <section> |
139 |
| - <Test foo={1}><span>asdf</span></Test> |
140 |
| - </section> |
141 |
| - ); |
142 |
| - |
143 |
| - expect(rendered) |
144 |
| - .to.equal(`<section><div foo="1"><span>asdf</span></div></section>`); |
145 |
| - |
146 |
| - expect(Test).to.have.been.calledOnce; |
147 |
| - |
148 |
| - expect(Test.prototype.render) |
149 |
| - .to.have.been.calledOnce |
150 |
| - .and.calledWithExactly( |
151 |
| - match({ |
152 |
| - foo: 1, |
153 |
| - children: [ |
154 |
| - match({ nodeName:'span', children:['asdf'] }) |
155 |
| - ] |
156 |
| - }), |
157 |
| - match({}) // empty state |
158 |
| - ); |
159 |
| - }); |
160 |
| - }); |
161 |
| - |
162 |
| - describe('className / class massaging', () => { |
163 |
| - it('should render class using className', () => { |
164 |
| - let rendered = render(<div className="foo bar" />); |
165 |
| - expect(rendered).to.equal('<div class="foo bar"></div>'); |
166 |
| - }); |
167 |
| - |
168 |
| - it('should render class using class', () => { |
169 |
| - let rendered = render(<div class="foo bar" />); |
170 |
| - expect(rendered).to.equal('<div class="foo bar"></div>'); |
171 |
| - }); |
172 |
| - |
173 |
| - it('should prefer className over class', () => { |
174 |
| - let rendered = render(<div class="foo" className="foo bar" />); |
175 |
| - expect(rendered).to.equal('<div class="foo bar"></div>'); |
176 |
| - }); |
177 |
| - }); |
178 |
| - }); |
179 |
| - |
180 |
| - describe('shallowRender()', () => { |
181 |
| - it('should not render nested components', () => { |
182 |
| - let Test = spy( ({ foo, children }) => <div bar={foo}><b>test child</b>{ children }</div> ); |
183 |
| - Test.displayName = 'Test'; |
184 |
| - |
185 |
| - let rendered = shallowRender( |
186 |
| - <section> |
187 |
| - <Test foo={1}><span>asdf</span></Test> |
188 |
| - </section> |
189 |
| - ); |
190 |
| - |
191 |
| - expect(rendered).to.equal(`<section><Test foo="1"><span>asdf</span></Test></section>`); |
192 |
| - expect(Test).not.to.have.been.called; |
193 |
| - }); |
194 |
| - |
195 |
| - it('should always render root component', () => { |
196 |
| - let Test = spy( ({ foo, children }) => <div bar={foo}><b>test child</b>{ children }</div> ); |
197 |
| - Test.displayName = 'Test'; |
198 |
| - |
199 |
| - let rendered = shallowRender( |
200 |
| - <Test foo={1}> |
201 |
| - <span>asdf</span> |
202 |
| - </Test> |
203 |
| - ); |
204 |
| - |
205 |
| - expect(rendered).to.equal(`<div bar="1"><b>test child</b><span>asdf</span></div>`); |
206 |
| - expect(Test).to.have.been.calledOnce; |
| 15 | + it('exposes shallowRender as a named export', () => { |
| 16 | + expect(shallowRender).to.be.a('function'); |
207 | 17 | });
|
208 | 18 | });
|
209 | 19 | });
|
0 commit comments