Skema: Errors

Show the properties of Errors

by kaelzhang

HTML

<script src="https://unpkg.com/skema/umd/jsfiddle.js"></script>
<script src="https://unpkg.com/skema/umd/skema.min.js"></script>

JavaScript

const {shape, type} = Skema

log('example: error, string key')

const A = shape({
	foo: Number
})

try {
	A.from({a: 'hahaha'})
} catch (e) {
	fail(e.message, e)
  fail('e.key', e.key)
}

log('example: error, array key')

const B = shape([Number])

try {
	B.from([1, 'hahaha'])
} catch (e) {
	fail(e.message, e)
  fail('e.key', e.key)
}

log('example: error, null key')

const C = type(Number)

try {
	C.from('hahaha')
} catch (e) {
	fail(e.message, e)
  fail('e.key', e.key)
}

log('example: initialization error')

throws(() => {
	shape({
  	foo: 'unknown'
  })
})