File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
packages/component/component Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -113,4 +113,44 @@ describe("LayForm", () => {
113
113
expect ( fn . mock . calls [ 0 ] [ 0 ] ) . toBeTruthy ( ) ;
114
114
} ) ;
115
115
} ) ;
116
+
117
+ describe ( "validator" , ( ) => {
118
+ function createForm ( ) {
119
+ const model = reactive ( {
120
+ account : "" ,
121
+ password : "" ,
122
+ } ) ;
123
+
124
+ const wrapper = mount ( {
125
+ setup ( ) {
126
+ return ( ) => (
127
+ < LayForm model = { model } >
128
+ < LayFormItem label = "账号" prop = "account" >
129
+ < LayInput v-model = { model . account } > </ LayInput >
130
+ </ LayFormItem >
131
+ < LayFormItem label = "密码" prop = "password" required = { true } >
132
+ < LayInput v-model = { model . password } > </ LayInput >
133
+ </ LayFormItem >
134
+ </ LayForm >
135
+ ) ;
136
+ } ,
137
+ } ) ;
138
+
139
+ return wrapper ;
140
+ }
141
+
142
+ test ( "单个 required form-item是否触发校验" , async ( ) => {
143
+ const wrapper = createForm ( ) ;
144
+
145
+ const formComponent = wrapper . findComponent ( LayForm ) ;
146
+
147
+ const fn = vi . fn ( ) ;
148
+
149
+ formComponent . vm . validate ( fn ) ;
150
+ await sleep ( 300 ) ;
151
+
152
+ expect ( fn ) . toHaveBeenCalled ( ) ;
153
+ expect ( fn . mock . calls [ 0 ] [ 0 ] ) . toBeFalsy ( ) ;
154
+ } ) ;
155
+ } ) ;
116
156
} ) ;
Original file line number Diff line number Diff line change @@ -177,6 +177,8 @@ const validate = (
177
177
clearValidate ();
178
178
}
179
179
});
180
+ } else {
181
+ resolve (undefined );
180
182
}
181
183
});
182
184
};
You can’t perform that action at this time.
0 commit comments