What is the easy way of loading LocaleKeys in unit tests.
@necipk you need LocaleKeys or localized keys?
In one of my unit test it throws exception with a text from LocaleKeys.mykey and as localization is not loaded in the unit test it gives an error.
I've got a simplest solution
...
import 'package:easy_localization/src/translations.dart';
import 'package:easy_localization/src/localization.dart';
...
class TranslationsMock extends Mock implements Translations {}
...
setUpAll(() async {
final translations = TranslationsMock();
when(translations.get("my_awesome_key")).thenReturn("Test");
Localization.load(Locale('en'), translations: translations);
});
...
test(...)
...
@Overman775 it should be great to get this snippet in the plugin documentation in a test part ;-)
I've got a simplest solution
... import 'package:easy_localization/src/translations.dart'; import 'package:easy_localization/src/localization.dart'; ... class TranslationsMock extends Mock implements Translations {} ... setUpAll(() async { final translations = TranslationsMock(); when(translations.get("my_awesome_key")).thenReturn("Test"); Localization.load(Locale('en'), translations: translations); }); ... test(...) ...@Overman775 it should be great to get this snippet in the plugin documentation in a test part ;-)
You should really think about adding this to the README.md since I almost dropped your lib because I could not find a solution at first!
Most helpful comment
I've got a simplest solution
@Overman775 it should be great to get this snippet in the plugin documentation in a test part ;-)