Skip to content

Commit 2c2923e

Browse files
author
Mateusz Puczynski
committed
Make errors and test more sensible
1 parent bbd8bdb commit 2c2923e

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/validate.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ function toErrorSchema(errors) {
7070
// "errors" (see `validate.createErrorHandler`).
7171
parent.__errors = parent.__errors.concat(message);
7272
} else {
73-
parent.__errors = [message];
73+
if (message) {
74+
parent.__errors = [message];
75+
}
7476
}
7577
return errorSchema;
7678
}, {});
@@ -201,7 +203,6 @@ export default function validateFormData(
201203
errors = transformErrors(errors);
202204
}
203205
const errorSchema = toErrorSchema(errors);
204-
205206
if (typeof customValidate !== "function") {
206207
return { errors, errorSchema };
207208
}

test/Form_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ describe("Form", () => {
19951995

19961996
const { comp } = createFormComponent(formProps);
19971997

1998-
expect(comp.state.errorSchema).eql({ __errors: [undefined] });
1998+
expect(comp.state.errorSchema).eql({});
19991999

20002000
setProps(comp, {
20012001
...formProps,
@@ -2013,7 +2013,7 @@ describe("Form", () => {
20132013

20142014
setProps(comp, formProps);
20152015

2016-
expect(comp.state.errorSchema).eql({ __errors: [undefined] });
2016+
expect(comp.state.errorSchema).eql({});
20172017
});
20182018
});
20192019
});

test/validate_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe("Validation", () => {
131131
stack: errMessage,
132132
},
133133
]);
134-
expect(errors.errorSchema).to.eql({ __errors: [undefined] });
134+
expect(errors.errorSchema).to.eql({});
135135
});
136136
it("should return a validation error about formData", () => {
137137
const errors = validateFormData(

0 commit comments

Comments
 (0)