Skip to content

Commit

Permalink
test: add a regression test for #177
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Jan 27, 2024
1 parent add7790 commit 731e2c6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/regressions/177.js
Original file line number Diff line number Diff line change
@@ -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()
})

0 comments on commit 731e2c6

Please sign in to comment.