File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -464,3 +464,37 @@ test('nullable type in the schema', (t) => {
464464 t . same ( stringify ( data ) , JSON . stringify ( data ) )
465465 t . same ( stringify ( null ) , JSON . stringify ( null ) )
466466} )
467+
468+ test ( 'throw an error if the value doesn\'t match the type' , ( t ) => {
469+ t . plan ( 2 )
470+
471+ const schema = {
472+ type : 'object' ,
473+ additionalProperties : false ,
474+ required : [ 'data' ] ,
475+ properties : {
476+ data : {
477+ type : 'array' ,
478+ minItems : 1 ,
479+ items : {
480+ oneOf : [
481+ {
482+ type : 'string'
483+ } ,
484+ {
485+ type : 'number'
486+ }
487+ ]
488+ }
489+ }
490+ }
491+ }
492+
493+ const stringify = build ( schema )
494+
495+ const validData = { data : [ 1 , 'testing' ] }
496+ t . equal ( stringify ( validData ) , JSON . stringify ( validData ) )
497+
498+ const invalidData = { data : [ false , 'testing' ] }
499+ t . throws ( ( ) => stringify ( invalidData ) )
500+ } )
You can’t perform that action at this time.
0 commit comments