diff --git a/tests/test_widget_removing.py b/tests/test_widget_removing.py index 5391fe7a0..b0da63d2e 100644 --- a/tests/test_widget_removing.py +++ b/tests/test_widget_removing.py @@ -108,3 +108,19 @@ async def test_remove_move_focus(): assert len(pilot.app.screen.walk_children(with_self=False)) == 6 assert pilot.app.focused is not None assert pilot.app.focused == buttons[9] + +async def test_remove_order(): + """The removal of a top-level widget should cause bottom-first removal.""" + + removals: list[str] = [] + + class Removable(Container): + def on_unmount( self, _ ): + removals.append(self.id if self.id is not None else "unknown") + + async with App().run_test() as pilot: + await pilot.app.mount( + Removable(Removable(Removable(id="grandchild"), id="child"), id="parent") + ) + await pilot.app.screen.children[0].remove() + assert removals == ["grandchild", "child", "parent"]