From 6fd4fc38889aa0f042da8e3c79fc13e18e4e63c1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sat, 24 Apr 2021 20:02:55 +0200 Subject: [PATCH] fix(const): type should not be added when using const --- index.js | 1 - test.js | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ad6c237..883c108 100644 --- a/index.js +++ b/index.js @@ -94,7 +94,6 @@ module.exports = { const (value) { return decorate(this, { - type: getJsonType(value), const: value }) }, diff --git a/test.js b/test.js index 4fdac2f..fd5ef44 100644 --- a/test.js +++ b/test.js @@ -115,11 +115,23 @@ test('enum() creates an enum from an array', function (t) { test('const() creates a const value', function (t) { const schema = ms.const('foo') assert.deepEqual(schema, { - type: 'string', const: 'foo' }) }) +test('const() creates a required const value', function (t) { + const schema = ms.obj({ + foo: ms.required.const('bar') + }) + assert.deepEqual(schema, { + type: 'object', + required: ['foo'], + properties: { + foo: {const: 'bar'} + } + }) +}) + test('arrayOf() creates an array with a type of its items', function (t) { const schema = ms.arrayOf('integer')