|
3 | 3 | NodeOpTypes,
|
4 | 4 | type TestElement,
|
5 | 5 | TestNodeTypes,
|
| 6 | + type VNode, |
6 | 7 | createBlock,
|
7 | 8 | createCommentVNode,
|
8 | 9 | createTextVNode,
|
@@ -316,6 +317,64 @@ describe('renderer: fragment', () => {
|
316 | 317 | )
|
317 | 318 | })
|
318 | 319 |
|
| 320 | + // #10547 |
| 321 | + test('`template` fragment w/ render function', () => { |
| 322 | + const renderFn = (vnode: VNode) => { |
| 323 | + return ( |
| 324 | + openBlock(), |
| 325 | + createBlock( |
| 326 | + Fragment, |
| 327 | + null, |
| 328 | + [createTextVNode('text'), (openBlock(), createBlock(vnode))], |
| 329 | + PatchFlags.STABLE_FRAGMENT, |
| 330 | + ) |
| 331 | + ) |
| 332 | + } |
| 333 | + |
| 334 | + const root = nodeOps.createElement('div') |
| 335 | + const foo = h('div', ['foo']) |
| 336 | + const bar = h('div', [h('div', 'bar')]) |
| 337 | + |
| 338 | + render(renderFn(foo), root) |
| 339 | + expect(serializeInner(root)).toBe(`text<div>foo</div>`) |
| 340 | + |
| 341 | + render(renderFn(bar), root) |
| 342 | + expect(serializeInner(root)).toBe(`text<div><div>bar</div></div>`) |
| 343 | + |
| 344 | + render(renderFn(foo), root) |
| 345 | + expect(serializeInner(root)).toBe(`text<div>foo</div>`) |
| 346 | + }) |
| 347 | + |
| 348 | + // #10547 |
| 349 | + test('`template` fragment w/ render function + keyed vnode', () => { |
| 350 | + const renderFn = (vnode: VNode) => { |
| 351 | + return ( |
| 352 | + openBlock(), |
| 353 | + createBlock( |
| 354 | + Fragment, |
| 355 | + null, |
| 356 | + [createTextVNode('text'), (openBlock(), createBlock(vnode))], |
| 357 | + PatchFlags.STABLE_FRAGMENT, |
| 358 | + ) |
| 359 | + ) |
| 360 | + } |
| 361 | + |
| 362 | + const root = nodeOps.createElement('div') |
| 363 | + const foo = h('div', { key: 1 }, [h('div', 'foo')]) |
| 364 | + const bar = h('div', { key: 2 }, [h('div', 'bar'), h('div', 'bar')]) |
| 365 | + |
| 366 | + render(renderFn(foo), root) |
| 367 | + expect(serializeInner(root)).toBe(`text<div><div>foo</div></div>`) |
| 368 | + |
| 369 | + render(renderFn(bar), root) |
| 370 | + expect(serializeInner(root)).toBe( |
| 371 | + `text<div><div>bar</div><div>bar</div></div>`, |
| 372 | + ) |
| 373 | + |
| 374 | + render(renderFn(foo), root) |
| 375 | + expect(serializeInner(root)).toBe(`text<div><div>foo</div></div>`) |
| 376 | + }) |
| 377 | + |
319 | 378 | // #6852
|
320 | 379 | test('`template` keyed fragment w/ text', () => {
|
321 | 380 | const root = nodeOps.createElement('div')
|
|
0 commit comments