Skip to content

Commit

Permalink
Add testcase from is-my-json-valid#161
Browse files Browse the repository at this point in the history
Refs: mafintosh/is-my-json-valid#161
Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
  • Loading branch information
ChALkeR and bahmutov committed Jun 29, 2020
1 parent 6465d3f commit 3d05c33
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,28 @@ tape('custom format', function(t) {
t.end()
})

tape('custom format string or null', function(t) {
const validate = validator(
{
type: 'object',
properties: {
foo: {
type: ['string', 'null'],
format: 'as',
},
},
},
{ formats: { as: /^a+$/ } }
)

t.notOk(validate({ foo: '' }), 'not as')
t.notOk(validate({ foo: 'bar' }), 'not as')
t.notOk(validate({ foo: 123 }), 'not as if number')
t.ok(validate({ foo: 'a' }), 'as')
t.ok(validate({ foo: null }), 'as')
t.end()
})

tape('custom format function', function(t) {
const validate = validator(
{
Expand Down

0 comments on commit 3d05c33

Please sign in to comment.