Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can write unit test?

kzjn10 opened this issue · comments

Please update the document to handle unit test.

This worked for me. Wanted to share in case it's helpful for someone else.

Future<Widget> makeTestableWidget() async {
  var delegate = await LocalizationDelegate.create(
    fallbackLocale: 'de',
    supportedLocales: ['de', 'en'],
    basePath: 'path_to_translations_folder',
  );

  return LocalizedApp(delegate, App());
}

void main() {
  group('use-case', () {
    testWidgets('test-case-1', (WidgetTester tester) async {
      var app = await makeTestableWidget();

      await tester.pumpWidget(app);
      await tester.pumpAndSettle();
      await expectLater(
          find.byType(app.runtimeType), matchesGoldenFile('<path_to_snapshot>'));
    });
  });
}