Commit 330dc94c authored by Dan Field's avatar Dan Field Committed by Jonah Williams

Check that ErrorWidget.builder is not modified after test (#30898)

parent 28cb589c
...@@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart';
void main() { void main() {
testWidgets('ErrorWidget.builder', (WidgetTester tester) async { testWidgets('ErrorWidget.builder', (WidgetTester tester) async {
final ErrorWidgetBuilder oldBuilder = ErrorWidget.builder;
ErrorWidget.builder = (FlutterErrorDetails details) { ErrorWidget.builder = (FlutterErrorDetails details) {
return const Text('oopsie!', textDirection: TextDirection.ltr); return const Text('oopsie!', textDirection: TextDirection.ltr);
}; };
...@@ -21,5 +22,6 @@ void main() { ...@@ -21,5 +22,6 @@ void main() {
); );
expect(tester.takeException().toString(), 'test'); expect(tester.takeException().toString(), 'test');
expect(find.text('oopsie!'), findsOneWidget); expect(find.text('oopsie!'), findsOneWidget);
ErrorWidget.builder = oldBuilder;
}); });
} }
...@@ -584,6 +584,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -584,6 +584,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
final bool autoUpdateGoldensBeforeTest = autoUpdateGoldenFiles; final bool autoUpdateGoldensBeforeTest = autoUpdateGoldenFiles;
final TestExceptionReporter reportTestExceptionBeforeTest = reportTestException; final TestExceptionReporter reportTestExceptionBeforeTest = reportTestException;
final ErrorWidgetBuilder errorWidgetBuilderBeforeTest = ErrorWidget.builder;
// run the test // run the test
await testBody(); await testBody();
...@@ -598,6 +599,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -598,6 +599,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
invariantTester(); invariantTester();
_verifyAutoUpdateGoldensUnset(autoUpdateGoldensBeforeTest); _verifyAutoUpdateGoldensUnset(autoUpdateGoldensBeforeTest);
_verifyReportTestExceptionUnset(reportTestExceptionBeforeTest); _verifyReportTestExceptionUnset(reportTestExceptionBeforeTest);
_verifyErrorWidgetBuilderUnset(errorWidgetBuilderBeforeTest);
_verifyInvariants(); _verifyInvariants();
} }
...@@ -667,6 +669,21 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -667,6 +669,21 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
}()); }());
} }
void _verifyErrorWidgetBuilderUnset(ErrorWidgetBuilder valueBeforeTest) {
assert(() {
if (ErrorWidget.builder != valueBeforeTest) {
FlutterError.reportError(FlutterErrorDetails(
exception: FlutterError(
'The value of ErrorWidget.builder was changed by the test.',
),
stack: StackTrace.current,
library: 'Flutter test framework',
));
}
return true;
}());
}
/// Called by the [testWidgets] function after a test is executed. /// Called by the [testWidgets] function after a test is executed.
void postTest() { void postTest() {
assert(inTest); assert(inTest);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment