@@ -43,6 +43,7 @@ describe('validateJsonLogicRules', () => {
4343 it ( 'returns empty array when validation data is not found' , ( ) => {
4444 const schema : NonBooleanJsfSchema = {
4545 'type' : 'object' ,
46+ 'title' : 'foo' ,
4647 'properties' : { } ,
4748 'x-jsf-logic-validations' : [ 'someValidation' ] ,
4849 }
@@ -54,8 +55,9 @@ describe('validateJsonLogicRules', () => {
5455 value : { } ,
5556 }
5657
57- const result = validateJsonLogicRules ( schema , jsonLogicContext )
58- expect ( result ) . toEqual ( [ ] )
58+ expect ( ( ) => validateJsonLogicRules ( schema , jsonLogicContext ) ) . toThrow (
59+ `[json-schema-form] json-logic error: "foo" required validation "someValidation" doesn't exist.` ,
60+ )
5961 } )
6062
6163 it ( 'returns validation error when rule evaluates to false' , ( ) => {
@@ -316,8 +318,9 @@ describe('validateJsonLogicRules', () => {
316318 } ,
317319 }
318320
319- const errors = validateSchema ( { num_guests : 4 , amount_of_snacks_to_bring : 3 } , schema )
320- expect ( errors ) . toHaveLength ( 0 )
321+ expect ( ( ) => validateSchema ( { num_guests : 4 , amount_of_snacks_to_bring : 3 } , schema ) ) . toThrow (
322+ `[json-schema-form] json-logic error: "Number of snacks to bring" required validation "invalid-rule" doesn't exist.` ,
323+ )
321324 expect ( jsonLogic . apply ) . not . toHaveBeenCalled ( )
322325 } )
323326
@@ -378,9 +381,10 @@ describe('validateJsonLogicComputedAttributes', () => {
378381 }
379382
380383 const jsonLogicContext : JsonLogicContext = { schema : { computedValues : { } } , value : { age : 16 } }
381- const result = validateJsonLogicComputedAttributes ( { age : 16 } , schema , { } , jsonLogicContext , [ ] )
384+ expect ( ( ) => validateJsonLogicComputedAttributes ( { age : 16 } , schema , { } , jsonLogicContext , [ ] ) ) . toThrow (
385+ `[json-schema-form] json-logic error: Computed value "nonexistentRule" has missing rule.` ,
386+ )
382387
383- expect ( result ) . toEqual ( [ ] )
384388 expect ( jsonLogic . apply ) . not . toHaveBeenCalled ( )
385389 } )
386390
@@ -570,10 +574,9 @@ describe('validateJsonLogicComputedAttributes', () => {
570574
571575 ( jsonLogic . apply as jest . Mock ) . mockReturnValue ( 15 )
572576
573- const result = validateSchema ( { someProperty : 10 } , schema )
574- expect ( result ) . toHaveLength ( 1 )
575- expect ( result [ 0 ] . validation ) . toBe ( 'minimum' )
576- expect ( result [ 0 ] . schema [ 'x-jsf-errorMessage' ] ?. minimum ) . toBe ( 'Must be at least {{invalidVar}} units' )
577+ expect ( ( ) => validateSchema ( { someProperty : 10 } , schema ) ) . toThrow (
578+ `[json-schema-form] json-logic error: Computed value "invalidVar" doesn't exist` ,
579+ )
577580 } )
578581 } )
579582} )
0 commit comments