I am trying to write unit tests in Dart/Flutter for my TextField validations. However, I have a little problem here because the tests are working, but I want to return the value with localization now.
How exactly do I implement this into the tests now?
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ValidationConstants {
static String? notEmpty(String? value, BuildContext context) {
if (value == null || value.isEmpty) {
return AppLocalizations.of(context)!.text_field_can_not_be_empty;
}
return null;
}
}
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('text field validations', () {
test('no empty text validation', () {
const emptyText = '';
const noEmptyText = 'Hello, World!';
// BuildContext is needed here
expect(ValidationConstants.notEmpty(emptyText, [...]).runtimeType, String);
expect(ValidationConstants.notEmpty(noEmptyText, [...]) == null, true);
});
});
}