import { JsonFile , JsonObject } from '../JsonFile' ; import { JsonSchema , IJsonSchemaErrorInfo } from '../JsonSchema' ; describe ( 'JsonSchema' , ( ) => { const schemaPath = `${ __dirname }/test-data/test-schema.json` ; const schema = JsonSchema . fromFile ( schemaPath ) ; test ( 'loadAndValidate successfully validates a JSON file' , ( ) => { const jsonPath = `${ __dirname }/test-data/test.json` ; const jsonObject = JsonFile . loadAndValidate ( jsonPath , schema ) ; expect ( jsonObject ) . toMatchObject ( { exampleString : 'This is a string' , exampleArray : [ 'apple' , 'banana' , 'coconut' ] } ) ; } ) ; test ( 'validateObjectWithCallback successfully reports a compound validation error' , ( ) => { const jsonPath2 = `${ __dirname }/test-data/test2.json` ; const jsonObject2 = JsonFile . load ( jsonPath2 ) ; const errorDetails = [ ] ; schema . validateObjectWithCallback ( jsonObject2 , ( errorInfo ) => { errorDetails . push ( errorInfo . details ) ; } ) ; expect ( errorDetails ) . toMatchSnapshot ( ) ; } ) ; } ) ;