@@ -1042,6 +1042,77 @@ Object.keys(testContexts).forEach((testKey) => {
1042
1042
} ) ;
1043
1043
} ) ;
1044
1044
1045
+ describe ( 'simultaneous sync and async validation' , ( ) => {
1046
+ it ( 'should execute sync and async validation simultaneously'
1047
+ + ' if specified' , ( ) => {
1048
+ const initialState = getInitialState ( { foo : '' } ) ;
1049
+ const reducer = formReducer ( 'test' ) ;
1050
+ const store = testCreateStore ( {
1051
+ testForm : reducer ,
1052
+ test : modelReducer ( 'test' , initialState ) ,
1053
+ } ) ;
1054
+ const syncValid = ( ) => true ;
1055
+ const asyncValid = ( ) => true ;
1056
+ const syncValidSpy = sinon . spy ( syncValid ) ;
1057
+ const asyncValidSpy = sinon . spy ( asyncValid ) ;
1058
+
1059
+ const field = TestUtils . renderIntoDocument (
1060
+ < Provider store = { store } >
1061
+ < Control . text
1062
+ model = "test.foo"
1063
+ validators = { { syncValidSpy } }
1064
+ validateOn = "change"
1065
+ asyncValidators = { { asyncValidSpy } }
1066
+ asyncValidateOn = "change"
1067
+ />
1068
+ </ Provider >
1069
+ ) ;
1070
+
1071
+ const control = TestUtils . findRenderedDOMComponentWithTag ( field , 'input' ) ;
1072
+
1073
+ control . value = 'testing' ;
1074
+
1075
+ TestUtils . Simulate . change ( control ) ;
1076
+
1077
+ assert . isTrue ( syncValidSpy . called ) ;
1078
+ assert . isTrue ( asyncValidSpy . called ) ;
1079
+ } ) ;
1080
+
1081
+ it ( 'should execute sync and async validation simultaneously'
1082
+ + ' if specified (with default validateOn)' , ( ) => {
1083
+ const initialState = getInitialState ( { foo : '' } ) ;
1084
+ const reducer = formReducer ( 'test' ) ;
1085
+ const store = testCreateStore ( {
1086
+ testForm : reducer ,
1087
+ test : modelReducer ( 'test' , initialState ) ,
1088
+ } ) ;
1089
+ const syncValid = ( ) => true ;
1090
+ const asyncValid = ( ) => true ;
1091
+ const syncValidSpy = sinon . spy ( syncValid ) ;
1092
+ const asyncValidSpy = sinon . spy ( asyncValid ) ;
1093
+
1094
+ const field = TestUtils . renderIntoDocument (
1095
+ < Provider store = { store } >
1096
+ < Control . text
1097
+ model = "test.foo"
1098
+ validators = { { syncValidSpy } }
1099
+ asyncValidators = { { asyncValidSpy } }
1100
+ asyncValidateOn = "change"
1101
+ />
1102
+ </ Provider >
1103
+ ) ;
1104
+
1105
+ const control = TestUtils . findRenderedDOMComponentWithTag ( field , 'input' ) ;
1106
+
1107
+ control . value = 'testing' ;
1108
+
1109
+ TestUtils . Simulate . change ( control ) ;
1110
+
1111
+ assert . isTrue ( syncValidSpy . called ) ;
1112
+ assert . isTrue ( asyncValidSpy . called ) ;
1113
+ } ) ;
1114
+ } ) ;
1115
+
1045
1116
describe ( 'validation after reset' , ( ) => {
1046
1117
const initialState = getInitialState ( { foo : '' } ) ;
1047
1118
const reducer = formReducer ( 'test' ) ;
0 commit comments