Skip to content

Commit

Permalink
fix: oneOf, notOneOf swallowing multiple errors (#1434)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Jenkins <adam.jenkins@aptos.com>
  • Loading branch information
akmjenkins and Adam Jenkins authored Aug 4, 2021
1 parent 7576cd8 commit 7842afb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@ export default abstract class BaseSchema<
let initialTests = [];

if (this._typeError) initialTests.push(this._typeError);
if (this._whitelistError) initialTests.push(this._whitelistError);
if (this._blacklistError) initialTests.push(this._blacklistError);

let finalTests = [];
if (this._whitelistError) finalTests.push(this._whitelistError);
if (this._blacklistError) finalTests.push(this._blacklistError);

runTests(
{
Expand All @@ -398,7 +400,7 @@ export default abstract class BaseSchema<

runTests(
{
tests: this.tests,
tests: this.tests.concat(finalTests),
args,
path,
sync,
Expand Down
20 changes: 20 additions & 0 deletions test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ describe('String types', () => {
]);
});

it('should check allowed values at the end',() => {
return Promise.all([
string()
.required('Required')
.notOneOf([ref('$someKey')])
.validate('',{context:{someKey:''}})
.should.be.rejected().then(err => {
err.type.should.equal('required')
}),
object({
email:string().required('Email Required'),
password:string().required('Password Required').notOneOf([ref('email')]),
}).validate({email:'',password:''},{abortEarly:false})
.should.be.rejected().then(err => {
err.errors.should.include('Email Required');
err.errors.should.include('Password Required');
})
]);
});

it('should validate transforms', function () {
return Promise.all([
string().trim().isValid(' 3 ').should.eventually().equal(true),
Expand Down

0 comments on commit 7842afb

Please sign in to comment.