Skip to content

Commit

Permalink
Add additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Feb 2, 2023
1 parent 92436d6 commit 4724c7d
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/browser/fragments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2914,4 +2914,54 @@ describe('Fragment', () => {
'<p>1. Original item first paragraph</p><p>2. Original item second paragraph</p><button>Click me</button>'
);
});

it('should efficiently unmount nested Fragment children when rerendering and reordering', () => {
/** @type {() => void} */
let toggle;

class App extends Component {
constructor(props) {
super(props);
this.state = { condition: true };
toggle = () => this.setState({ condition: !this.state.condition });
}

render() {
return this.state.condition ? (
<Fragment>
<div>1</div>
<Fragment>
<div>A</div>
<div>B</div>
</Fragment>
<div>2</div>
</Fragment>
) : (
<Fragment>
<Fragment>
<div>A</div>
</Fragment>
<div>1</div>
<div>2</div>
</Fragment>
);
}
}

clearLog();
render(<App />, scratch);
expect(scratch.innerHTML).to.equal(
[div(1), div('A'), div('B'), div(2)].join('')
);

clearLog();
toggle();
rerender();

expect(scratch.innerHTML).to.equal([div('A'), div(1), div(2)].join(''));
expectDomLogToBe([
'<div>B.remove()',
'<div>1A2.insertBefore(<div>1, <div>2)'
]);
});
});

0 comments on commit 4724c7d

Please sign in to comment.