mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add some more framework.dart tests (#7469)
This commit is contained in:
parent
6737712067
commit
3c33bb4697
@ -156,7 +156,7 @@ void main() {
|
||||
|
||||
testWidgets('Setting parent state during build is forbidden', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(new BadWidgetParent());
|
||||
expect(tester.takeException(), isNotNull);
|
||||
expect(tester.takeException(), isFlutterError);
|
||||
await tester.pumpWidget(new Container());
|
||||
});
|
||||
|
||||
@ -225,4 +225,4 @@ void main() {
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,14 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class TestState extends State<StatefulWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) => null;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('UniqueKey control test', (WidgetTester tester) async {
|
||||
Key key = new UniqueKey();
|
||||
@ -25,6 +31,19 @@ void main() {
|
||||
expect(keyA, isNot(equals(keyB)));
|
||||
});
|
||||
|
||||
testWidgets('GlobalObjectKey control test', (WidgetTester tester) async {
|
||||
Object a = new Object();
|
||||
Object b = new Object();
|
||||
Key keyA = new GlobalObjectKey(a);
|
||||
Key keyA2 = new GlobalObjectKey(a);
|
||||
Key keyB = new GlobalObjectKey(b);
|
||||
|
||||
expect(keyA, hasOneLineDescription);
|
||||
expect(keyA, equals(keyA2));
|
||||
expect(keyA.hashCode, equals(keyA2.hashCode));
|
||||
expect(keyA, isNot(equals(keyB)));
|
||||
});
|
||||
|
||||
testWidgets('GlobalKey duplication', (WidgetTester tester) async {
|
||||
Key key = new GlobalKey(debugLabel: 'problematic');
|
||||
|
||||
@ -55,7 +74,7 @@ void main() {
|
||||
],
|
||||
));
|
||||
|
||||
expect(tester.takeException(), isNotNull);
|
||||
expect(tester.takeException(), isFlutterError);
|
||||
});
|
||||
|
||||
testWidgets('GlobalKey notification exception handling', (WidgetTester tester) async {
|
||||
@ -78,4 +97,50 @@ void main() {
|
||||
expect(tester.takeException(), isNotNull);
|
||||
expect(didReceiveCallback, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('Defunct setState throws exception', (WidgetTester tester) async {
|
||||
StateSetter setState;
|
||||
|
||||
await tester.pumpWidget(new StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setter) {
|
||||
setState = setter;
|
||||
return new Container();
|
||||
},
|
||||
));
|
||||
|
||||
// Control check that setState doesn't throw an exception.
|
||||
setState(() { });
|
||||
|
||||
await tester.pumpWidget(new Container());
|
||||
|
||||
expect(() { setState(() { }); }, throwsFlutterError);
|
||||
});
|
||||
|
||||
testWidgets('State toString', (WidgetTester tester) async {
|
||||
TestState state = new TestState();
|
||||
expect(state.toString(), contains('no config'));
|
||||
});
|
||||
|
||||
testWidgets('debugPrintGlobalKeyedWidgetLifecycle control test', (WidgetTester tester) async {
|
||||
expect(debugPrintGlobalKeyedWidgetLifecycle, isFalse);
|
||||
|
||||
final DebugPrintCallback oldCallback = debugPrint;
|
||||
debugPrintGlobalKeyedWidgetLifecycle = true;
|
||||
|
||||
List<String> log = <String>[];
|
||||
debugPrint = (String message, { int wrapWidth }) {
|
||||
log.add(message);
|
||||
};
|
||||
|
||||
GlobalKey key = new GlobalKey();
|
||||
await tester.pumpWidget(new Container(key: key));
|
||||
expect(log, isEmpty);
|
||||
await tester.pumpWidget(new Placeholder());
|
||||
debugPrint = oldCallback;
|
||||
debugPrintGlobalKeyedWidgetLifecycle = false;
|
||||
|
||||
expect(log.length, equals(2));
|
||||
expect(log[0], matches('Deactivated'));
|
||||
expect(log[1], matches('Discarding .+ from inactive elements list.'));
|
||||
});
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ void main() {
|
||||
]
|
||||
)
|
||||
);
|
||||
expect(tester.takeException(), isNotNull);
|
||||
expect(tester.takeException(), isFlutterError);
|
||||
|
||||
await tester.pumpWidget(new Stack());
|
||||
|
||||
@ -276,7 +276,7 @@ void main() {
|
||||
)
|
||||
)
|
||||
);
|
||||
expect(tester.takeException(), isNotNull);
|
||||
expect(tester.takeException(), isFlutterError);
|
||||
|
||||
await tester.pumpWidget(
|
||||
new Stack()
|
||||
@ -339,4 +339,20 @@ void main() {
|
||||
new TestParentData(top: 10.0, left: 10.0),
|
||||
]);
|
||||
});
|
||||
|
||||
testWidgets('Parent data invalid ancestor', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(new Row(
|
||||
children: <Widget>[
|
||||
new Stack(
|
||||
children: <Widget>[
|
||||
new Expanded(
|
||||
child: new Container()
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
expect(tester.takeException(), isFlutterError);
|
||||
});
|
||||
}
|
||||
|
@ -66,6 +66,12 @@ const Matcher isNotInCard = const _IsNotInCard();
|
||||
/// empty, and does not contain the default `Instance of ...` string.
|
||||
const Matcher hasOneLineDescription = const _HasOneLineDescription();
|
||||
|
||||
/// A matcher for functions that throw [FlutterError].
|
||||
const Matcher throwsFlutterError = const Throws(isFlutterError);
|
||||
|
||||
/// A matcher for [FlutterError].
|
||||
const Matcher isFlutterError = const isInstanceOf<FlutterError>();
|
||||
|
||||
/// Asserts that two [double]s are equal, within some tolerated error.
|
||||
///
|
||||
/// Two values are considered equal if the difference between them is within
|
||||
@ -268,4 +274,4 @@ class _MoreOrLessEquals extends Matcher {
|
||||
|
||||
@override
|
||||
Description describe(Description description) => description.add('$value (±$epsilon)');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user