Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
MIT License
403 stars 118 forks source link

How can write unit test? #59

Closed kzjn10 closed 2 years ago

kzjn10 commented 3 years ago

Please update the document to handle unit test.

Akash-M commented 3 years ago

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>'));
    });
  });
}