Skip to content

Commit 896a80e

Browse files
authored
Merge pull request #113 from antmendoza/improve_validation_message
improve validation message by adding data
2 parents b24ccad + 8c2515b commit 896a80e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/lib/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const validate = (typeName: string, data: any): boolean => {
1515
console.warn(validateFn.errors);
1616
const firstError: DefinedError = (validateFn.errors as DefinedError[])[0];
1717
throw new Error(
18-
`${typeName} is invalid: ${firstError.instancePath} | ${firstError.schemaPath} | ${firstError.message}`
18+
`${typeName} is invalid: ${firstError.instancePath} | ${firstError.schemaPath} | ${firstError.message}
19+
data: ${data}`
1920
);
2021
}
2122
return true;

tests/lib/utils.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { validate } from '../../src/lib/utils';
2+
3+
describe('validate', () => {
4+
it('should throw an error containing the provided data', () => {
5+
expect( () => validate('End', "any text")).toThrowError(/any text/);
6+
});
7+
8+
it('should return true for valid objects', () => {
9+
expect(validate('End', false)).toBeTruthy("Expected function validate to return true for valid objects");
10+
});
11+
12+
});

0 commit comments

Comments
 (0)