Skip to content

Commit a712622

Browse files
committed
test: Update coverage
1 parent 6f401e5 commit a712622

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

src/utils/validateUtil.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,7 @@ export function validateRules(
206206
summaryPromise = (
207207
validateFirst ? finishOnFirstFailed(rulePromises) : finishOnAllFailed(rulePromises)
208208
).then((errors: RuleError[]): RuleError[] | Promise<RuleError[]> => {
209-
if (!errors.length) {
210-
return [];
211-
}
212-
209+
// Always change to rejection for Field to catch
213210
return Promise.reject<RuleError[]>(errors);
214211
});
215212
}

tests/validate-warning.test.tsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { mount } from 'enzyme';
44
import Form from '../src';
55
import InfoField, { Input } from './common/InfoField';
66
import { changeValue, matchError } from './common';
7+
import type { Rule } from '@/interface';
78

89
describe('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

Comments
 (0)