Skip to content

Commit df25a1b

Browse files
committed
Add test case to verify proper disposal of selectedIdEditStateProvider
1 parent 1513cfe commit df25a1b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/providers/ui_providers_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,35 @@ void main() {
299299
// Verify that the selectedIdEditStateProvider is null
300300
expect(container.read(selectedIdEditStateProvider), null);
301301
});
302+
testWidgets("It should be properly disposed", (tester) async {
303+
await tester.pumpWidget(
304+
const ProviderScope(
305+
child: MaterialApp(
306+
home: CollectionPane(),
307+
),
308+
),
309+
);
310+
311+
// Grab the Dashboard widget and its ProviderContainer
312+
final collectionPane = tester.element(find.byType(CollectionPane));
313+
final container = ProviderScope.containerOf(collectionPane);
314+
315+
// Pumping a different widget to remove the CollectionPane from the widget tree
316+
await tester.pumpWidget(
317+
const MaterialApp(
318+
home: Scaffold(body: Text('Foo')),
319+
),
320+
);
321+
322+
// Verify that the ProviderContainer has been disposed
323+
// by trying to read from disposed container
324+
bool isDisposed = false;
325+
try {
326+
container.read(selectedIdEditStateProvider);
327+
} catch (e) {
328+
isDisposed = true;
329+
}
330+
expect(isDisposed, true);
331+
});
302332
});
303333
}

0 commit comments

Comments
 (0)