freeman-check
Advanced tools
Comparing version 3.0.4 to 3.0.5
{ | ||
"name": "freeman-check", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "Easy type and format checking on JavaScript objects", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -74,2 +74,6 @@ "use strict"; | ||
break; | ||
case 'enum': | ||
subject = error.property.replace('instance.', ''); | ||
problem = 'needs to be one of ' + error.argument.map(s => `"${s}"`).join(', '); | ||
break; | ||
} | ||
@@ -76,0 +80,0 @@ // concatenate all validation errors. |
@@ -15,2 +15,3 @@ "use strict"; | ||
website: { type: 'string', format: 'uri' }, | ||
status: { type: 'string', enum: ['active', 'inactive', 'pending'] }, | ||
}, | ||
@@ -91,3 +92,26 @@ required: ['name', 'email', 'favourite_films'], | ||
}); | ||
describe('Enum check', () => { | ||
it('should throw an error if object has incorrect enum value', () => { | ||
const object = { | ||
name, | ||
email, | ||
favourite_films, | ||
status: 'unknown', // Incorrect enum value | ||
}; | ||
(0, chai_1.expect)(() => check(schema).test(object)).to.throw(CheckError_1.CheckError, '`status` needs to be one of "active", "inactive", "pending".'); | ||
}); | ||
}); | ||
describe('Multiple errors', () => { | ||
it('should be able to return multiple errors joined together', () => { | ||
const object = { | ||
name, | ||
email: 'invalid-email', | ||
favourite_films: 'Transformers', | ||
website: 'invalid-website', | ||
status: 'unknown', // Incorrect enum value | ||
}; | ||
(0, chai_1.expect)(() => check(schema).test(object)).to.throw(CheckError_1.CheckError, '`email` needs to be formatted as `email`. `favourite_films` needs to be an `array`. `website` needs to be formatted as `uri`. `status` needs to be one of "active", "inactive", "pending".'); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18583
342