Skip to content

Commit

Permalink
fix: prevent unhandled Promise rejection when returning rejected Prom…
Browse files Browse the repository at this point in the history
…ise inside test function (#1327)
  • Loading branch information
danielrearden authored Apr 4, 2021
1 parent 91ace1e commit 5eda549
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/createValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions test/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5eda549

Please sign in to comment.