From 3047b33c7bf76f0e4335725efa2b5175192322f9 Mon Sep 17 00:00:00 2001 From: Dmitrii Maganov Date: Thu, 7 Feb 2019 15:17:44 +0300 Subject: [PATCH] fix: noUnknown() overriding (#452) --- src/object.js | 2 +- test/object.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/object.js b/src/object.js index f8b3f96ea..417e83b5a 100644 --- a/src/object.js +++ b/src/object.js @@ -240,7 +240,7 @@ inherits(ObjectSchema, MixedSchema, { }, }); - if (noAllow) next._options.stripUnknown = true; + next._options.stripUnknown = noAllow; return next; }, diff --git a/test/object.js b/test/object.js index 543fd3999..2069d5122 100644 --- a/test/object.js +++ b/test/object.js @@ -329,6 +329,17 @@ describe('Object types', () => { ]); }); + it('should work with noUnknown override', async () => { + let inst = object() + .shape({ + prop: mixed(), + }) + .noUnknown() + .noUnknown(false); + + await inst.validate({ extra: 'field' }).should.become({ extra: 'field' }); + }); + it('should strip specific fields', () => { let inst = object().shape({ prop: mixed().strip(false),