@@ -4,6 +4,7 @@ import { mount } from 'enzyme';
44import Form from '../src' ;
55import InfoField , { Input } from './common/InfoField' ;
66import { changeValue , matchError } from './common' ;
7+ import type { Rule } from '@/interface' ;
78
89describe ( 'Form.WarningValidate' , ( ) => {
910 it ( 'required' , async ( ) => {
@@ -28,35 +29,57 @@ describe('Form.WarningValidate', () => {
2829 } ) ;
2930
3031 describe ( 'validateFirst should not block error' , ( ) => {
31- function testValidateFirst ( name : string , validateFirst : boolean | 'parallel' ) {
32+ function testValidateFirst (
33+ name : string ,
34+ validateFirst : boolean | 'parallel' ,
35+ additionalRule ?: Rule ,
36+ errorMessage ?: string ,
37+ ) {
3238 it ( name , async ( ) => {
39+ const rules = [
40+ additionalRule ,
41+ {
42+ type : 'string' ,
43+ len : 10 ,
44+ warningOnly : true ,
45+ } ,
46+ {
47+ type : 'url' ,
48+ } ,
49+ {
50+ type : 'string' ,
51+ len : 20 ,
52+ warningOnly : true ,
53+ } ,
54+ ] ;
55+
3356 const wrapper = mount (
3457 < Form >
3558 < InfoField
3659 name = "name"
3760 validateFirst = { validateFirst }
38- rules = { [
39- {
40- type : 'string' ,
41- len : 10 ,
42- warningOnly : true ,
43- } ,
44- {
45- type : 'url' ,
46- } ,
47- ] }
61+ rules = { rules . filter ( r => r ) as any }
4862 >
4963 < Input />
5064 </ InfoField >
5165 </ Form > ,
5266 ) ;
5367
5468 await changeValue ( wrapper , 'bamboo' ) ;
55- matchError ( wrapper , "'name' is not a valid url" , false ) ;
69+ matchError ( wrapper , errorMessage || "'name' is not a valid url" , false ) ;
5670 } ) ;
5771 }
5872
5973 testValidateFirst ( 'default' , true ) ;
74+ testValidateFirst (
75+ 'default' ,
76+ true ,
77+ {
78+ type : 'string' ,
79+ len : 3 ,
80+ } ,
81+ "'name' must be exactly 3 characters" ,
82+ ) ;
6083 testValidateFirst ( 'parallel' , 'parallel' ) ;
6184 } ) ;
6285} ) ;
0 commit comments