Skip to content

Commit

Permalink
backport test from #3738
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 26, 2022
1 parent 1660ed1 commit 515f15a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/browser/fragments.test.js
Expand Up @@ -1502,6 +1502,63 @@ describe('Fragment', () => {
);
});

it('should swap nested fragments correctly', () => {
let swap;
class App extends Component {
constructor(props) {
super(props);
this.state = { first: true };
}

render() {
if (this.state.first) {
return (
<Fragment>
{
<Fragment>
<p>1. Original item first paragraph</p>
</Fragment>
}
<p>2. Original item second paragraph</p>
<button onClick={(swap = () => this.setState({ first: false }))}>
Click me
</button>
</Fragment>
);
}
return (
<Fragment>
<p>1. Second item first paragraph</p>
<Fragment>
<p>2. Second item second paragraph</p>
<div />
</Fragment>
<button onClick={(swap = () => this.setState({ first: true }))}>
Click me
</button>
</Fragment>
);
}
}

render(<App />, scratch);
expect(scratch.innerHTML).to.equal(
'<p>1. Original item first paragraph</p><p>2. Original item second paragraph</p><button>Click me</button>'
);

swap();
rerender();
expect(scratch.innerHTML).to.equal(
'<p>1. Second item first paragraph</p><p>2. Second item second paragraph</p><div></div><button>Click me</button>'
);

swap();
rerender();
expect(scratch.innerHTML).to.equal(
'<p>1. Original item first paragraph</p><p>2. Original item second paragraph</p><button>Click me</button>'
);
});

it('should preserve state with reordering in multiple levels with lots of Fragment siblings', () => {
// Also fails if the # of divs outside the Fragment equals or exceeds
// the # inside the Fragment for both conditions
Expand Down

0 comments on commit 515f15a

Please sign in to comment.