Skip to content

Commit

Permalink
Add test for removing children of memoed components (#4210)
Browse files Browse the repository at this point in the history
Repro from issue #2619
  • Loading branch information
andrewiggins authored Nov 14, 2023
1 parent 056a890 commit 1e14862
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/browser/keys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,44 @@ describe('keys', () => {
]);
});

it('should properly remove children of memoed components', () => {
const values = [1, 2, 3, 4, 5, 6, 7, 8, 9];

class Item extends Component {
shouldComponentUpdate(props) {
return props.value !== this.props.value;
}

render() {
return <li>{this.props.value}</li>;
}
}

function App({ values }) {
return (
<ul>
{values.map(value => (
<Item key={value} value={value} />
))}
</ul>
);
}

render(<App values={values} />, scratch);
expect(scratch.textContent).to.equal(values.join(''));

clearLog();
values.splice(3, 3);

render(<App values={values} />, scratch);
expect(scratch.textContent).to.equal(values.join(''));
expect(getLog()).to.deep.equal([
'<li>4.remove()',
'<li>5.remove()',
'<li>6.remove()'
]);
});

it("should not preserve state when a component's keys are different", () => {
const Stateful = createStateful('Stateful');

Expand Down

0 comments on commit 1e14862

Please sign in to comment.