Skip to content

Commit

Permalink
Merge pull request #60 from seegno/enhancement/error-args
Browse files Browse the repository at this point in the history
Update validation to always return error arguments
  • Loading branch information
Micael Rodrigues authored May 30, 2022
2 parents cde9cab + bbe6c44 commit 0faa51e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function getErrorArgs(error: ValidationError) {
return { min: error.params.limit };

default:
return;
return error.params;
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/src/hooks/use-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ describe('useForm hook', () => {

expect(result.current.state.fields.errors).toEqual({
foo: {
args: { format: 'foo' },
rule: 'format'
}
});
Expand Down Expand Up @@ -644,6 +645,7 @@ describe('useForm hook', () => {

expect(result.current.state.fields.errors).toEqual({
foo: {
args: {},
rule: 'isFoo'
}
});
Expand Down
9 changes: 9 additions & 0 deletions test/src/utils/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ describe('validate', () => {

expect(result).toEqual({
foo: {
args: { type: 'string' },
rule: 'type'
},
'foo-bar': {
args: { type: 'string' },
rule: 'type'
}
});
Expand All @@ -49,6 +51,7 @@ describe('validate', () => {

expect(result).toEqual({
foo: {
args: { missingProperty: 'foo' },
rule: 'required'
}
});
Expand All @@ -65,6 +68,7 @@ describe('validate', () => {

expect(result).toEqual({
foo: {
args: { additionalProperty: 'foo' },
rule: 'additionalProperties'
}
});
Expand Down Expand Up @@ -269,6 +273,7 @@ describe('validate', () => {

expect(result).toEqual({
'foo.bar.qux': {
args: { type: 'string' },
rule: 'type'
}
});
Expand Down Expand Up @@ -299,6 +304,7 @@ describe('validate', () => {

expect(result).toEqual({
'foo[0].bar[0]': {
args: { type: 'string' },
rule: 'type'
}
});
Expand All @@ -322,6 +328,7 @@ describe('validate', () => {

expect(result).toEqual({
'foo[0][0]': {
args: { type: 'string' },
rule: 'type'
}
});
Expand Down Expand Up @@ -352,6 +359,7 @@ describe('validate', () => {

expect(result).toEqual({
foo: {
args: { format: 'foo' },
rule: 'format'
}
});
Expand Down Expand Up @@ -387,6 +395,7 @@ describe('validate', () => {

expect(result).toEqual({
foo: {
args: {},
rule: 'isFoo'
}
});
Expand Down

0 comments on commit 0faa51e

Please sign in to comment.