Skip to content

Instantly share code, notes, and snippets.

@hyochan
Last active April 15, 2020 16:34
Show Gist options
  • Save hyochan/9aa7ede3af173ed536158f97d970031b to your computer and use it in GitHub Desktop.
Save hyochan/9aa7ede3af173ed536158f97d970031b to your computer and use it in GitHub Desktop.
localized_widget_test_legacy.dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:localized_app_example/widgets/my_widget.dart' show MyWidget;
Widget makeTestableWidget({ Widget child }) {
return MediaQuery(
data: MediaQueryData(),
child: MaterialApp(
localizationsDelegates: [
LocalizationDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
home: child,
),
);
};
void main() {
testWidgets("Widget", (WidgetTester tester) async{
await tester.pumpWidget(makeTestableWidget(child: MyWidget()));
await tester.pumpAndSettle();
var findByText = find.byType(Text);
print(findByText.evaluate());
expect(findByText.evaluate().isEmpty, false);
expect(find.text('Loading') findsOneWidget);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment