@@ -847,6 +847,74 @@ describe('ngModel', function() {
847
847
expect ( ctrl . $valid ) . toBe ( true ) ;
848
848
} ) ;
849
849
850
+ // See also the test on L886.
851
+ fit ( 'should demonstrate how synchronous validators work now' , function ( ) {
852
+ var curry = function ( v ) {
853
+ return function ( ) {
854
+ return v ;
855
+ } ;
856
+ } ;
857
+
858
+ var tester = function ( v , e ) {
859
+ ctrl . $modelValue = undefined ;
860
+ ctrl . $validators . a = curry ( v ) ;
861
+
862
+ ctrl . $validate ( ) ;
863
+ expect ( ctrl . $valid ) . toBe ( e ) ;
864
+ } ;
865
+
866
+ // False tests
867
+ tester ( false , false ) ;
868
+ tester ( undefined , undefined ) ;
869
+ tester ( null , true ) ;
870
+ tester ( 0 , true ) ;
871
+ tester ( NaN , true ) ;
872
+ tester ( '' , true ) ;
873
+
874
+ // True tests
875
+ tester ( true , true ) ;
876
+ tester ( 1 , true ) ;
877
+ tester ( '0' , true ) ;
878
+ tester ( 'false' , true ) ;
879
+ tester ( [ ] , true ) ;
880
+ tester ( { } , true ) ;
881
+ } ) ;
882
+
883
+ // Flip this test with the one above (L851) as well as line L606 with L607 in `ngModel.js`
884
+ // The differences between the two would likely being a breaking change
885
+ // Though the feature it is breaking was undocumented.
886
+ xit ( 'should demonstrate how synchronous validators will work after this change' , function ( ) {
887
+ var curry = function ( v ) {
888
+ return function ( ) {
889
+ return v ;
890
+ } ;
891
+ } ;
892
+
893
+ var tester = function ( v , e ) {
894
+ ctrl . $modelValue = undefined ;
895
+ ctrl . $validators . a = curry ( v ) ;
896
+
897
+ ctrl . $validate ( ) ;
898
+ expect ( ctrl . $valid ) . toBe ( e ) ;
899
+ } ;
900
+
901
+ // False tests
902
+ tester ( false , false ) ;
903
+ tester ( undefined , false ) ;
904
+ tester ( null , false ) ;
905
+ tester ( 0 , false ) ;
906
+ tester ( NaN , false ) ;
907
+ tester ( '' , false ) ;
908
+
909
+ // True tests
910
+ tester ( true , true ) ;
911
+ tester ( 1 , true ) ;
912
+ tester ( '0' , true ) ;
913
+ tester ( 'false' , true ) ;
914
+ tester ( [ ] , true ) ;
915
+ tester ( { } , true ) ;
916
+ } ) ;
917
+
850
918
851
919
it ( 'should register invalid validations on the $error object' , function ( ) {
852
920
var curry = function ( v ) {
0 commit comments