Skip to content

Commit bc6452c

Browse files
committed
Wrote tests for the new validators
1 parent 5679930 commit bc6452c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/form_builder_validators_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,41 @@ void main() {
208208
expect(validator(4444), isNotNull);
209209
}));
210210

211+
testWidgets(
212+
'FormBuilderValidators.maxWordsCount',
213+
(WidgetTester tester) => testValidations(tester, (context) {
214+
final validator = FormBuilderValidators.maxWordsCount(5);
215+
// Pass
216+
expect(validator(null), isNull);
217+
expect(validator(''), isNull);
218+
expect(validator('the quick brown'), isNull);
219+
expect(validator('The quick brown fox jumps'), isNull);
220+
// Fail
221+
expect(validator('The quick brown fox jumps over'), isNotNull);
222+
expect(validator('The quick brown fox jumps over the lazy dog'),
223+
isNotNull);
224+
}));
225+
226+
testWidgets(
227+
'FormBuilderValidators.minWordsCount',
228+
(WidgetTester tester) => testValidations(tester, (context) {
229+
final validator = FormBuilderValidators.minWordsCount(5);
230+
// Pass
231+
expect(validator('The quick brown fox jumps'), isNull);
232+
expect(validator('The quick brown fox jumps over'), isNull);
233+
expect(validator('The quick brown fox jumps over the lazy dog'),
234+
isNull);
235+
// Fail
236+
expect(validator(null), isNotNull);
237+
expect(validator(''), isNotNull);
238+
expect(validator('The quick brown'), isNotNull);
239+
// Advanced
240+
final validatorAllowEmpty =
241+
FormBuilderValidators.minWordsCount(5, allowEmpty: true);
242+
expect(validatorAllowEmpty(null), isNull);
243+
expect(validatorAllowEmpty(''), isNull);
244+
}));
245+
211246
testWidgets(
212247
'FormBuilderValidators.email',
213248
(WidgetTester tester) => testValidations(tester, (context) {

0 commit comments

Comments
 (0)