Skip to content

Instantly share code, notes, and snippets.

@hyochan
Last active April 15, 2020 16:33
Show Gist options
  • Save hyochan/642cdff6e5bac0027723604df6f9ee9e to your computer and use it in GitHub Desktop.
Save hyochan/642cdff6e5bac0027723604df6f9ee9e to your computer and use it in GitHub Desktop.
flutter_localized_example/test/widget_test.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(isTest: true),
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