diff --git a/test/regressions/177.js b/test/regressions/177.js new file mode 100644 index 0000000..a175666 --- /dev/null +++ b/test/regressions/177.js @@ -0,0 +1,63 @@ +'use strict' + +const tape = require('tape') +const { validator } = require('../../') + +tape('regression #177', (t) => { + const obj = { type: 'object' } + + for (const [a, b] of [[{}, obj], [obj, {}], [obj, obj]]) { + t.doesNotThrow(() => { + const validate = validator({ + required: ['type'], + discriminator: { propertyName: 'type' }, + properties: { + type: { + enum: ['noop', 'foo'], + }, + }, + oneOf: [ + { + type: 'object', + properties: { type: { const: 'noop' } }, + }, + { + ...a, + required: ['method'], + discriminator: { propertyName: 'method' }, + properties: { + type: { const: 'foo' }, + method: { + enum: ['bar', 'buzz'], + }, + }, + oneOf: [ + { + ...b, + properties: { + method: { const: 'bar' }, + }, + }, + { + ...b, + properties: { + method: { const: 'buzz' }, + }, + }, + ], + }, + ], + }) + + t.notOk(validate({}), '{}') + t.ok(validate({ type: 'noop' }), "{ type: 'noop' }") + t.notOk(validate({ type: 'no' }), "{ type: 'no' }") + t.notOk(validate({ type: 'bar' }), "{ type: 'bar' }") + t.notOk(validate({ type: 'foo' }), "{ type: 'foo' }") + t.ok(validate({ type: 'foo', method: 'bar' }), "{ type: 'foo', method: 'bar' }") + t.notOk(validate({ type: 'foo', method: 'fuzz' }), "{ type: 'foo', method: 'fuzz' }") + }) + } + + t.end() +})