You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.5 KiB

4 years ago
'use strict'
const test = require('tap').test
const fjs = require('..')
function build (opts) {
return fjs({
title: 'default string',
type: 'object',
properties: {
firstName: {
type: 'string'
}
},
required: ['firstName']
}, opts)
}
test('activate debug mode', t => {
t.plan(2)
const debugMode = build({ debugMode: true })
t.type(debugMode, Array)
t.like(debugMode.toString.toString(), 'join', 'to string override')
})
test('activate debug mode truthy', t => {
t.plan(2)
const debugMode = build({ debugMode: 'yes' })
t.type(debugMode, Array)
t.like(debugMode.toString.toString(), 'join', 'to string override')
})
test('to string auto-consistent', t => {
t.plan(2)
const debugMode = build({ debugMode: 1 })
t.type(debugMode, Array)
const str = debugMode.toString()
const compiled = fjs.restore(str)
const tobe = JSON.stringify({ firstName: 'Foo' })
t.deepEquals(compiled({ firstName: 'Foo', surname: 'bar' }), tobe, 'surname evicted')
})
test('to string auto-consistent with ajv', t => {
t.plan(2)
const debugMode = fjs({
title: 'object with multiple types field',
type: 'object',
properties: {
str: {
anyOf: [{
type: 'string'
}, {
type: 'boolean'
}]
}
}
}, { debugMode: 1 })
t.type(debugMode, Array)
const str = debugMode.toString()
const compiled = fjs.restore(str)
const tobe = JSON.stringify({ str: 'Foo' })
t.deepEquals(compiled({ str: 'Foo', void: 'me' }), tobe)
})