This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Patch 14734 boolean sync validators #15208
Closed
BobChao87
wants to merge
5
commits into
angular:master
from
BobChao87:patch-14734-boolean-sync-validators
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a812954
Demonstrate tests for issue #14734
BobChao87 1a1d0fb
fix(ngModel): treat synchronous validators as boolean always
BobChao87 7e4bf60
fix(ngModel): treat synchronous validators as boolean always
BobChao87 5ce3053
fix(ngModel): treat synchronous validators as boolean always
BobChao87 64c6d39
fix(ngModel): treat synchronous validators as boolean always
BobChao87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -847,6 +847,38 @@ describe('ngModel', function() { | |
expect(ctrl.$valid).toBe(true); | ||
}); | ||
|
||
it('should treat all responses as boolean for synchronous validators', function() { | ||
var curry = function(v) { | ||
return function() { | ||
return v; | ||
}; | ||
}; | ||
|
||
var tester = function(v, e) { | ||
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. Nit: I would prefer a more descriptive name, such as |
||
ctrl.$modelValue = undefined; | ||
ctrl.$validators.a = curry(v); | ||
|
||
ctrl.$validate(); | ||
expect(ctrl.$valid).toBe(e); | ||
}; | ||
|
||
// False tests | ||
tester(false, false); | ||
tester(undefined, false); | ||
tester(null, false); | ||
tester(0, false); | ||
tester(NaN, false); | ||
tester('', false); | ||
|
||
// True tests | ||
tester(true, true); | ||
tester(1, true); | ||
tester('0', true); | ||
tester('false', true); | ||
tester([], true); | ||
tester({}, true); | ||
}); | ||
|
||
|
||
it('should register invalid validations on the $error object', function() { | ||
var curry = function(v) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You don't need a new function for this. You can use the internal helper:
valueFn()
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.
Interesting, I'll make the switch. I was actually hoping to talk about the
curry()
anyways, because it's now used three times in this file (hence why I used it in the first place). I'll submit a separate PR to fix the others.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.
Good catch! Feel free to change all other instances too.