Skip to content

Commit 1e14862

Browse files
authored
Add test for removing children of memoed components (#4210)
Repro from issue #2619
1 parent 056a890 commit 1e14862

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/browser/keys.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,44 @@ describe('keys', () => {
443443
]);
444444
});
445445

446+
it('should properly remove children of memoed components', () => {
447+
const values = [1, 2, 3, 4, 5, 6, 7, 8, 9];
448+
449+
class Item extends Component {
450+
shouldComponentUpdate(props) {
451+
return props.value !== this.props.value;
452+
}
453+
454+
render() {
455+
return <li>{this.props.value}</li>;
456+
}
457+
}
458+
459+
function App({ values }) {
460+
return (
461+
<ul>
462+
{values.map(value => (
463+
<Item key={value} value={value} />
464+
))}
465+
</ul>
466+
);
467+
}
468+
469+
render(<App values={values} />, scratch);
470+
expect(scratch.textContent).to.equal(values.join(''));
471+
472+
clearLog();
473+
values.splice(3, 3);
474+
475+
render(<App values={values} />, scratch);
476+
expect(scratch.textContent).to.equal(values.join(''));
477+
expect(getLog()).to.deep.equal([
478+
'<li>4.remove()',
479+
'<li>5.remove()',
480+
'<li>6.remove()'
481+
]);
482+
});
483+
446484
it("should not preserve state when a component's keys are different", () => {
447485
const Stateful = createStateful('Stateful');
448486

0 commit comments

Comments
 (0)