Skip to content

Commit 4300be9

Browse files
joebalancioMarsup
authored andcommitted
Create extended Joi from a new instance of Any (#934)
Fix missing top-level methods
1 parent 32bf602 commit 4300be9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ internals.root = function () {
186186

187187
this.assert(extensions, root.extensionsSchema);
188188

189-
const joi = Object.assign({}, this);
189+
const joi = Object.create(this);
190190

191191
for (let i = 0; i < extensions.length; ++i) {
192192
const extension = extensions[i];

test/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,5 +2646,17 @@ describe('Joi', () => {
26462646
done();
26472647
});
26482648
});
2649+
2650+
it('should return a custom Joi as an instance of Any', (done) => {
2651+
2652+
const customJoi = Joi.extend({
2653+
name: 'myType'
2654+
});
2655+
2656+
const Any = require('../lib/any');
2657+
expect(customJoi).to.be.an.instanceof(Any);
2658+
done();
2659+
});
2660+
26492661
});
26502662
});

0 commit comments

Comments
 (0)