diff --git a/src/util/createValidation.ts b/src/util/createValidation.ts index a6cefefee..3df3728be 100644 --- a/src/util/createValidation.ts +++ b/src/util/createValidation.ts @@ -120,7 +120,7 @@ export default function createValidation(config: { if (ValidationError.isError(validOrError)) cb(validOrError); else if (!validOrError) cb(createError()); else cb(null, validOrError); - }); + }).catch(cb); } catch (err) { cb(err); } diff --git a/test/mixed.js b/test/mixed.js index 01ae82a8b..f422405ae 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -529,6 +529,16 @@ describe('Mixed Types ', () => { }); }); + it('should fail when the test function returns a rejected Promise', async () => { + let inst = string().test(() => { + return Promise.reject(new Error('oops an error occurred')) + }); + + return inst + .validate('joe') + .should.be.rejected(); + }); + describe('withMutation', () => { it('should pass the same instance to a provided function', () => { let inst = mixed();