@@ -15,6 +15,10 @@ describe('uiValidate', function () {
15
15
return valueToValidate ;
16
16
} ;
17
17
18
+ var undefinedValidator = function ( ) {
19
+ return undefined ;
20
+ } ;
21
+
18
22
beforeEach ( module ( 'ui.validate' ) ) ;
19
23
beforeEach ( inject ( function ( $rootScope , $compile ) {
20
24
@@ -36,17 +40,27 @@ describe('uiValidate', function () {
36
40
37
41
scope . validate = trueValidator ;
38
42
compileAndDigest ( '<input name="input" ng-model="value" ui-validate="\'validate($value)\'">' , scope ) ;
39
- expect ( scope . form . input . $valid ) . toBeTruthy ( ) ;
43
+ expect ( scope . form . input . $valid ) . toBe ( true ) ;
40
44
expect ( scope . form . input . $error ) . toEqual ( { } ) ;
41
45
} ) ) ;
42
46
43
47
it ( 'should mark input as invalid if initial model is invalid' , inject ( function ( ) {
44
48
45
49
scope . validate = falseValidator ;
46
50
compileAndDigest ( '<input name="input" ng-model="value" ui-validate="\'validate($value)\'">' , scope ) ;
47
- expect ( scope . form . input . $valid ) . toBeFalsy ( ) ;
51
+ expect ( scope . form . input . $valid ) . toBe ( false ) ;
48
52
expect ( scope . form . input . $error ) . toEqual ( { validator : true } ) ;
49
53
} ) ) ;
54
+
55
+ it ( 'should not corrupt the NgModelController and the FormController if the validator returns undefined' , inject ( function ( ) {
56
+
57
+ scope . validate = undefinedValidator ;
58
+ compileAndDigest ( '<input name="input" ng-model="value" ui-validate="\'validate($value)\'">' , scope ) ;
59
+ expect ( scope . form . input . $valid ) . toBe ( false ) ;
60
+ expect ( scope . form . $valid ) . toBe ( false ) ;
61
+ expect ( scope . form . input . $error ) . toEqual ( { validator : true } ) ;
62
+ } ) ) ;
63
+
50
64
} ) ;
51
65
52
66
describe ( 'validation on model change' , function ( ) {
@@ -56,10 +70,10 @@ describe('uiValidate', function () {
56
70
scope . value = false ;
57
71
scope . validate = passedValueValidator ;
58
72
compileAndDigest ( '<input name="input" ng-model="value" ui-validate="\'validate($value)\'">' , scope ) ;
59
- expect ( scope . form . input . $valid ) . toBeFalsy ( ) ;
73
+ expect ( scope . form . input . $valid ) . toBe ( false ) ;
60
74
61
75
scope . $apply ( 'value = true' ) ;
62
- expect ( scope . form . input . $valid ) . toBeTruthy ( ) ;
76
+ expect ( scope . form . input . $valid ) . toBe ( true ) ;
63
77
} ) ) ;
64
78
} ) ;
65
79
@@ -75,12 +89,12 @@ describe('uiValidate', function () {
75
89
scope . value = false ;
76
90
scope . validate = passedValueValidator ;
77
91
var inputElm = compileAndDigest ( '<input name="input" ng-model="value" ui-validate="\'validate($value)\'">' , scope ) ;
78
- expect ( scope . form . input . $valid ) . toBeFalsy ( ) ;
92
+ expect ( scope . form . input . $valid ) . toBe ( false ) ;
79
93
80
94
inputElm . val ( 'true' ) ;
81
95
inputElm . trigger ( ( sniffer . hasEvent ( 'input' ) ? 'input' : 'change' ) ) ;
82
96
83
- expect ( scope . form . input . $valid ) . toBeTruthy ( ) ;
97
+ expect ( scope . form . input . $valid ) . toBe ( true ) ;
84
98
} ) ;
85
99
} ) ;
86
100
@@ -92,9 +106,9 @@ describe('uiValidate', function () {
92
106
scope . validate2 = falseValidator ;
93
107
94
108
compileAndDigest ( '<input name="input" ng-model="value" ui-validate="{key1 : \'validate1($value)\', key2 : \'validate2($value)\'}">' , scope ) ;
95
- expect ( scope . form . input . $valid ) . toBeFalsy ( ) ;
96
- expect ( scope . form . input . $error . key1 ) . toBeFalsy ( ) ;
97
- expect ( scope . form . input . $error . key2 ) . toBeTruthy ( ) ;
109
+ expect ( scope . form . input . $valid ) . toBe ( false ) ;
110
+ expect ( scope . form . input . $error . key1 ) . toBeUndefined ( ) ;
111
+ expect ( scope . form . input . $error . key2 ) . toBe ( true ) ;
98
112
} ) ;
99
113
} ) ;
100
114
0 commit comments