|
1 |
| -import { createApp, h } from 'vue' |
2 |
| -import { renderToString, renderComponent, renderSlot } from '../src' |
| 1 | +import { createApp, h, createCommentVNode } from 'vue' |
| 2 | +import { renderToString, renderComponent, renderSlot, escapeHtml } from '../src' |
3 | 3 |
|
4 | 4 | describe('ssr: renderToString', () => {
|
5 | 5 | describe('components', () => {
|
@@ -251,21 +251,82 @@ describe('ssr: renderToString', () => {
|
251 | 251 | })
|
252 | 252 | })
|
253 | 253 |
|
254 |
| - describe('scopeId', () => { |
255 |
| - // TODO |
256 |
| - }) |
| 254 | + describe('vnode element', () => { |
| 255 | + test('props', async () => { |
| 256 | + expect( |
| 257 | + await renderToString( |
| 258 | + h('div', { id: 'foo&', class: ['bar', 'baz'] }, 'hello') |
| 259 | + ) |
| 260 | + ).toBe(`<div id="foo&" class="bar baz">hello</div>`) |
| 261 | + }) |
257 | 262 |
|
258 |
| - describe('vnode', () => { |
259 |
| - test('text children', () => {}) |
| 263 | + test('text children', async () => { |
| 264 | + expect(await renderToString(h('div', 'hello'))).toBe(`<div>hello</div>`) |
| 265 | + }) |
260 | 266 |
|
261 |
| - test('array children', () => {}) |
| 267 | + test('array children', async () => { |
| 268 | + expect( |
| 269 | + await renderToString( |
| 270 | + h('div', [ |
| 271 | + 'foo', |
| 272 | + h('span', 'bar'), |
| 273 | + [h('span', 'baz')], |
| 274 | + createCommentVNode('qux') |
| 275 | + ]) |
| 276 | + ) |
| 277 | + ).toBe( |
| 278 | + `<div>foo<span>bar</span><!----><span>baz</span><!----><!--qux--></div>` |
| 279 | + ) |
| 280 | + }) |
| 281 | + |
| 282 | + test('void elements', async () => { |
| 283 | + expect(await renderToString(h('input'))).toBe(`<input>`) |
| 284 | + }) |
262 | 285 |
|
263 |
| - test('void elements', () => {}) |
| 286 | + test('innerHTML', async () => { |
| 287 | + expect( |
| 288 | + await renderToString( |
| 289 | + h( |
| 290 | + 'div', |
| 291 | + { |
| 292 | + innerHTML: `<span>hello</span>` |
| 293 | + }, |
| 294 | + 'ignored' |
| 295 | + ) |
| 296 | + ) |
| 297 | + ).toBe(`<div><span>hello</span></div>`) |
| 298 | + }) |
264 | 299 |
|
265 |
| - test('innerHTML', () => {}) |
| 300 | + test('textContent', async () => { |
| 301 | + expect( |
| 302 | + await renderToString( |
| 303 | + h( |
| 304 | + 'div', |
| 305 | + { |
| 306 | + textContent: `<span>hello</span>` |
| 307 | + }, |
| 308 | + 'ignored' |
| 309 | + ) |
| 310 | + ) |
| 311 | + ).toBe(`<div>${escapeHtml(`<span>hello</span>`)}</div>`) |
| 312 | + }) |
266 | 313 |
|
267 |
| - test('textContent', () => {}) |
| 314 | + test('textarea value', async () => { |
| 315 | + expect( |
| 316 | + await renderToString( |
| 317 | + h( |
| 318 | + 'textarea', |
| 319 | + { |
| 320 | + value: `<span>hello</span>` |
| 321 | + }, |
| 322 | + 'ignored' |
| 323 | + ) |
| 324 | + ) |
| 325 | + ).toBe(`<textarea>${escapeHtml(`<span>hello</span>`)}</textarea>`) |
| 326 | + }) |
| 327 | + }) |
268 | 328 |
|
269 |
| - test('textarea value', () => {}) |
| 329 | + describe('scopeId', () => { |
| 330 | + // TODO |
270 | 331 | })
|
271 | 332 | })
|
0 commit comments