diff --git a/src/schema.ts b/src/schema.ts index 20dfed46c..89b783a83 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -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( { @@ -398,7 +400,7 @@ export default abstract class BaseSchema< runTests( { - tests: this.tests, + tests: this.tests.concat(finalTests), args, path, sync, diff --git a/test/string.js b/test/string.js index eaed09260..008782a2e 100644 --- a/test/string.js +++ b/test/string.js @@ -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),