From 73e64f155ef4d17fa24cd77ef4b0d61e8abd8710 Mon Sep 17 00:00:00 2001 From: Joseph Balancio Date: Sat, 25 Jun 2016 20:17:35 -0700 Subject: [PATCH 1/2] Create extended Joi from a new instance of Any --- lib/index.js | 2 +- test/index.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index c170bcb7b..1b0643387 100755 --- a/lib/index.js +++ b/lib/index.js @@ -186,7 +186,7 @@ internals.root = function () { this.assert(extensions, root.extensionsSchema); - const joi = Object.assign({}, this); + const joi = Object.assign(new Any().clone(), this); for (let i = 0; i < extensions.length; ++i) { const extension = extensions[i]; diff --git a/test/index.js b/test/index.js index d0de2b1bd..71cd66421 100755 --- a/test/index.js +++ b/test/index.js @@ -2646,5 +2646,17 @@ describe('Joi', () => { done(); }); }); + + it('should return a custom Joi as an instance of Any', (done) => { + + const customJoi = Joi.extend({ + name: 'myType' + }); + + const Any = require('../lib/any'); + expect(customJoi).to.be.an.instanceof(Any); + done(); + }); + }); }); From 56f257cad697ec08961c1a24501224e01f25f584 Mon Sep 17 00:00:00 2001 From: Joseph Balancio Date: Mon, 27 Jun 2016 13:52:09 -0700 Subject: [PATCH 2/2] Use Object.create instead --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 1b0643387..3ed003de0 100755 --- a/lib/index.js +++ b/lib/index.js @@ -186,7 +186,7 @@ internals.root = function () { this.assert(extensions, root.extensionsSchema); - const joi = Object.assign(new Any().clone(), this); + const joi = Object.create(this); for (let i = 0; i < extensions.length; ++i) { const extension = extensions[i];