From b958b8750d48557dca52e67863afef114212d0b2 Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Tue, 25 Jun 2024 21:55:34 -0700 Subject: [PATCH] Fix leaky tests. (#150817) --- packages/flutter/test/cupertino/button_test.dart | 6 ++++++ packages/flutter/test/widgets/undo_history_test.dart | 3 +++ 2 files changed, 9 insertions(+) diff --git a/packages/flutter/test/cupertino/button_test.dart b/packages/flutter/test/cupertino/button_test.dart index 39b22e5359..dbbc52bb7e 100644 --- a/packages/flutter/test/cupertino/button_test.dart +++ b/packages/flutter/test/cupertino/button_test.dart @@ -492,6 +492,8 @@ void main() { testWidgets('Button can be focused and has default colors', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(debugLabel: 'Button'); + addTearDown(focusNode.dispose); + tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; const Border defaultFocusBorder = Border.fromBorderSide( BorderSide( @@ -540,6 +542,8 @@ void main() { testWidgets('Button configures focus color', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(debugLabel: 'Button'); + addTearDown(focusNode.dispose); + tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; const Color focusColor = CupertinoColors.systemGreen; @@ -576,6 +580,8 @@ void main() { testWidgets('CupertinoButton.onFocusChange callback', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(debugLabel: 'CupertinoButton'); + addTearDown(focusNode.dispose); + bool focused = false; await tester.pumpWidget( CupertinoApp( diff --git a/packages/flutter/test/widgets/undo_history_test.dart b/packages/flutter/test/widgets/undo_history_test.dart index d4f5b083e8..657bb5fe8d 100644 --- a/packages/flutter/test/widgets/undo_history_test.dart +++ b/packages/flutter/test/widgets/undo_history_test.dart @@ -32,6 +32,7 @@ void main() { testWidgets('UndoHistory widget registers as global undo/redo client', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(debugLabel: 'UndoHistory Node'); + addTearDown(focusNode.dispose); final GlobalKey undoHistoryGlobalKey = GlobalKey(); final ValueNotifier value = ValueNotifier(0); addTearDown(value.dispose); @@ -68,6 +69,7 @@ void main() { testWidgets('UndoHistory widget deregisters as global undo/redo client when it loses focus', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(debugLabel: 'UndoHistory Node'); + addTearDown(focusNode.dispose); final GlobalKey undoHistoryGlobalKey = GlobalKey(); final ValueNotifier value = ValueNotifier(0); addTearDown(value.dispose); @@ -105,6 +107,7 @@ void main() { testWidgets('UndoHistory widget deregisters as global undo/redo client when disposed', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(debugLabel: 'UndoHistory Node'); + addTearDown(focusNode.dispose); final GlobalKey undoHistoryGlobalKey = GlobalKey(); final ValueNotifier value = ValueNotifier(0); addTearDown(value.dispose);