Unverified Commit 0556e14f authored by Vyacheslav Egorov's avatar Vyacheslav Egorov Committed by GitHub

Strong mode fixes in tests (#14520)

* Use explicit types for onClick handler in diagnostics_test.

This test formats it to string and expects exact match.

Before this change onClick had type () => dynamic in Dart 1 and () => Null in
Dart 2.

* Fix strong mode issues in packages/flutter/test/material/dropdown_test.dart

Pass explicit type argument to renderObjectList(...) in expressions like

     List<RenderBox> l = tester.renderObjectList(...).toList();

Dart 2 mode inference is not strong enough to infer RenderBox as a type argument
fto renderObjectList and passes RenderObject instead, which later leads to
runtime check failures (because List<RenderObject> is not List<RenderBox>).

* Fix strong mode issues in packages/flutter/test/material/theme_test.dart.

Pass type argument explicity to widgetList. Dart 2 type inference can't infer
it by itself.

* Fix strong mode issue packages/flutter/test/widgets/unique_widget_test.dart

Pass correct type argument to GlobalKey.

* Fix type annotation in packages/flutter/test/material/app_test.dart.

pushNamed returns Future<Object> not Future<String>.
parent 8acb6888
......@@ -970,7 +970,8 @@ void main() {
});
test('missing callback property test', () {
final Function onClick = () {};
void onClick() { }
final ObjectFlagProperty<Function> present = new ObjectFlagProperty<Function>(
'onClick',
onClick,
......@@ -982,7 +983,7 @@ void main() {
ifNull: 'disabled',
);
expect(present.toString(), equals('onClick: Closure: () => dynamic'));
expect(present.toString(), equals('onClick: Closure: () => void'));
expect(present.isFiltered(DiagnosticLevel.fine), isTrue);
expect(present.value, equals(onClick));
expect(missing.toString(), equals('disabled'));
......
......@@ -173,7 +173,7 @@ void main() {
});
testWidgets('Return value from pop is correct', (WidgetTester tester) async {
Future<String> result;
Future<Object> result;
await tester.pumpWidget(
new MaterialApp(
home: new Builder(
......
......@@ -93,7 +93,7 @@ class _TestAppState extends State<TestApp> {
// The RenderParagraphs should be aligned, i.e. they should have the same
// size and location.
void checkSelectedItemTextGeometry(WidgetTester tester, String value) {
final List<RenderBox> boxes = tester.renderObjectList(find.byKey(new ValueKey<String>(value + 'Text'))).toList();
final List<RenderBox> boxes = tester.renderObjectList<RenderBox>(find.byKey(new ValueKey<String>(value + 'Text'))).toList();
expect(boxes.length, equals(2));
final RenderBox box0 = boxes[0];
final RenderBox box1 = boxes[1];
......@@ -232,7 +232,7 @@ void main() {
);
await tester.tap(find.text(value));
await tester.pump();
final List<RenderBox> itemBoxes = tester.renderObjectList(find.byKey(itemKey)).toList();
final List<RenderBox> itemBoxes = tester.renderObjectList<RenderBox>(find.byKey(itemKey)).toList();
expect(itemBoxes[0].localToGlobal(Offset.zero).dx, equals(0.0));
expect(itemBoxes[1].localToGlobal(Offset.zero).dx, equals(16.0));
expect(itemBoxes[1].size.width, equals(800.0 - 16.0 * 2));
......@@ -354,7 +354,7 @@ void main() {
// The selected dropdown item is both in menu we just popped up, and in
// the IndexedStack contained by the dropdown button. Both of them should
// have the same vertical center as the button.
final List<RenderBox> itemBoxes = tester.renderObjectList(find.byKey(const ValueKey<String>('two'))).toList();
final List<RenderBox> itemBoxes = tester.renderObjectList<RenderBox>(find.byKey(const ValueKey<String>('two'))).toList();
expect(itemBoxes.length, equals(2));
// When isDense is true, the button's height is reduced. The menu items'
......
......@@ -252,7 +252,7 @@ void main() {
await tester.tap(find.text('SHOW'));
await tester.pump(const Duration(seconds: 1));
final List<Material> materials = tester.widgetList(find.byType(Material)).toList();
final List<Material> materials = tester.widgetList<Material>(find.byType(Material)).toList();
expect(materials.length, equals(2));
expect(materials[0].color, green); // app scaffold
expect(materials[1].color, green); // dialog scaffold
......
......@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
class TestUniqueWidget extends UniqueWidget<TestUniqueWidgetState> {
const TestUniqueWidget({ GlobalKey key }) : super(key: key);
const TestUniqueWidget({ GlobalKey<TestUniqueWidgetState> key }) : super(key: key);
@override
TestUniqueWidgetState createState() => new TestUniqueWidgetState();
......@@ -19,7 +19,7 @@ class TestUniqueWidgetState extends State<TestUniqueWidget> {
void main() {
testWidgets('Unique widget control test', (WidgetTester tester) async {
final TestUniqueWidget widget = new TestUniqueWidget(key: new GlobalKey());
final TestUniqueWidget widget = new TestUniqueWidget(key: new GlobalKey<TestUniqueWidgetState>());
await tester.pumpWidget(widget);
......
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