Skip to content

Commit

Permalink
Merge pull request #170 from hckrnews/feature/fix-custom-type-validation
Browse files Browse the repository at this point in the history
Fix the custom type error validation
  • Loading branch information
w3nl authored Apr 16, 2021
2 parents 57554e8 + 0b8c695 commit e09bfc8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckrnews/validator",
"version": "4.2.2",
"version": "4.2.3",
"description": "Object validator",
"main": "src/validator.js",
"files": [
Expand Down
4 changes: 3 additions & 1 deletion src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class Validator {
if (!(fieldType in types)) {
const validationMethod = `validate${value.constructor.name}`;

return this[validationMethod](value, fieldType);
return this[validationMethod]
? this[validationMethod](value, fieldType)
: false;
}

const type = types[fieldType];
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const test2 = new Test2('me');

const testCases = [
{
description: 'A valid test',
description: 'A valid test with a custom type',
input: {
name: 'test',
test: test2,
Expand All @@ -20,6 +20,16 @@ const testCases = [
expectedValue: true,
expectedErrors: [],
},
{
description: 'A invalid test with a custom type',
input: {
name: 'test',
test: 'test',
},
schema: test1Schema,
expectedValue: false,
expectedErrors: [['test', Test2]],
},
{
description: 'A valid bar',
input: {
Expand Down

0 comments on commit e09bfc8

Please sign in to comment.