|
1 | 1 | import { render, shallowRender } from '../src';
|
2 |
| -import { h, Component, createContext } from 'preact'; |
| 2 | +import { h, Component, createContext, Fragment } from 'preact'; |
3 | 3 | import { useState, useContext, useEffect } from 'preact/hooks';
|
4 | 4 | import chai, { expect } from 'chai';
|
5 | 5 | import { spy, stub, match } from 'sinon';
|
@@ -608,6 +608,67 @@ describe('render', () => {
|
608 | 608 | });
|
609 | 609 | });
|
610 | 610 |
|
| 611 | + describe('Fragments', () => { |
| 612 | + it('should skip Fragment node', () => { |
| 613 | + let html = render(<div><Fragment>foo</Fragment></div>); |
| 614 | + expect(html).to.equal('<div>foo</div>'); |
| 615 | + }); |
| 616 | + |
| 617 | + it('should skip Fragment node with multiple children', () => { |
| 618 | + let html = render( |
| 619 | + <div> |
| 620 | + <Fragment> |
| 621 | + foo |
| 622 | + <span>bar</span> |
| 623 | + </Fragment> |
| 624 | + </div> |
| 625 | + ); |
| 626 | + expect(html).to.equal('<div>foo<span>bar</span></div>'); |
| 627 | + }); |
| 628 | + |
| 629 | + it('should skip Fragment node with multiple children #2', () => { |
| 630 | + let html = render( |
| 631 | + <div> |
| 632 | + <Fragment> |
| 633 | + <div>foo</div> |
| 634 | + <div>bar</div> |
| 635 | + </Fragment> |
| 636 | + </div> |
| 637 | + ); |
| 638 | + expect(html).to.equal('<div><div>foo</div><div>bar</div></div>'); |
| 639 | + }); |
| 640 | + |
| 641 | + it('should skip Fragment even if it has props', () => { |
| 642 | + let html = render( |
| 643 | + <div> |
| 644 | + <Fragment key="2">foo</Fragment> |
| 645 | + </div> |
| 646 | + ); |
| 647 | + expect(html).to.equal('<div>foo</div>'); |
| 648 | + }); |
| 649 | + |
| 650 | + it('should skip sibling Fragments', () => { |
| 651 | + let html = render( |
| 652 | + <div> |
| 653 | + <Fragment>foo</Fragment> |
| 654 | + <Fragment>bar</Fragment> |
| 655 | + </div> |
| 656 | + ); |
| 657 | + expect(html).to.equal('<div>foobar</div>'); |
| 658 | + }); |
| 659 | + |
| 660 | + it('should skip nested Fragments', () => { |
| 661 | + let html = render( |
| 662 | + <div> |
| 663 | + <Fragment> |
| 664 | + <Fragment>foo</Fragment> |
| 665 | + </Fragment> |
| 666 | + </div> |
| 667 | + ); |
| 668 | + expect(html).to.equal('<div>foo</div>'); |
| 669 | + }); |
| 670 | + }); |
| 671 | + |
611 | 672 | describe('hooks', () => {
|
612 | 673 | it('should not crash with hooks', () => {
|
613 | 674 | function Foo() {
|
|
0 commit comments