-
Notifications
You must be signed in to change notification settings - Fork 106
Fix for fb: group with DateTime or TimeOfDay value and a validator as array #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -411,6 +411,35 @@ void main() { | |||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| test('Build a group with default datetime value and a validator as array', () { | ||||||||||||||||||||||||
| // Given: a form group builder creation | ||||||||||||||||||||||||
| final requiredValidator = Validators.required; | ||||||||||||||||||||||||
| final value = DateTime.now(); | ||||||||||||||||||||||||
| final form = fb.group({ | ||||||||||||||||||||||||
| 'control': [value, requiredValidator], | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Expect a form group created | ||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||
| form.control('control'), | ||||||||||||||||||||||||
| isA<FormControl<DateTime>>(), | ||||||||||||||||||||||||
| reason: | ||||||||||||||||||||||||
| '${form.control('control').runtimeType} is not instance of FormControl<DateTime>', | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||
| form.control('control').value, | ||||||||||||||||||||||||
| value, | ||||||||||||||||||||||||
| reason: 'control default value not set', | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||
| form.control('control').validators, | ||||||||||||||||||||||||
| [requiredValidator], | ||||||||||||||||||||||||
| reason: 'not set required validator' | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
Comment on lines
+435
to
+439
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify these two assertions into a single one by comparing the
Suggested change
|
||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| test('Build a group with default TimeOfDay value as array', () { | ||||||||||||||||||||||||
| // Given: a form group builder creation | ||||||||||||||||||||||||
| final value = TimeOfDay.now(); | ||||||||||||||||||||||||
|
|
@@ -432,6 +461,34 @@ void main() { | |||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| test('Build a group with default TimeOfDay value and a validator as array', () { | ||||||||||||||||||||||||
| // Given: a form group builder creation | ||||||||||||||||||||||||
| final requiredValidator = Validators.required; | ||||||||||||||||||||||||
| final value = TimeOfDay.now(); | ||||||||||||||||||||||||
| final form = fb.group({ | ||||||||||||||||||||||||
| 'control': [value, requiredValidator], | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Expect a form group created | ||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||
| form.control('control'), | ||||||||||||||||||||||||
| isA<FormControl<TimeOfDay>>(), | ||||||||||||||||||||||||
| reason: | ||||||||||||||||||||||||
| '${form.control('control').runtimeType} is not instance of FormControl<TimeOfDay>', | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
Comment on lines
+474
to
+479
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For type checks in tests, it's more idiomatic to use the
Suggested change
|
||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||
| form.control('control').value, | ||||||||||||||||||||||||
| value, | ||||||||||||||||||||||||
| reason: 'control default value not set', | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||
| form.control('control').validators, | ||||||||||||||||||||||||
| [requiredValidator], | ||||||||||||||||||||||||
| reason: 'not set required validator' | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
Comment on lines
+485
to
+489
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify these two assertions into a single one by comparing the
Suggested change
|
||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| test('Build a state with ', () { | ||||||||||||||||||||||||
| // Given: a state creation | ||||||||||||||||||||||||
| final state = fb.state(value: 'name', disabled: true); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For type checks in tests, it's more idiomatic to use the
isA<T>()matcher. It provides better error messages on failure, especially if the control isnull.