@@ -3,7 +3,7 @@ import { assert } from 'chai';
33import { evaluate , JSONPointerEvaluateError } from '../../src/index.js' ;
44
55describe ( 'evaluate' , function ( ) {
6- context ( 'given trace option' , function ( ) {
6+ context ( 'given trace option as object ' , function ( ) {
77 specify ( 'should trace successful evaluation' , function ( ) {
88 const data = { a : { b : 'c' } } ;
99 const trace = { } ;
@@ -88,19 +88,40 @@ describe('evaluate', function () {
8888 } ) ;
8989
9090 specify ( 'should produce error message with tracing info' , function ( ) {
91+ const trace = { } ;
92+
9193 assert . throws (
92- ( ) => evaluate ( { a : { b : 'c' } } , '1' , { trace : { } } ) ,
94+ ( ) => evaluate ( { a : { b : 'c' } } , '1' , { trace } ) ,
9395 JSONPointerEvaluateError ,
9496 'Invalid JSON Pointer: "1". Syntax error at position 0, expected "/"' ,
9597 ) ;
98+ assert . lengthOf ( trace . steps , 1 ) ;
9699 } ) ;
100+ } ) ;
97101
98- specify ( 'should produce error message without tracking info' , function ( ) {
102+ context ( 'given trace option as boolean' , function ( ) {
103+ specify ( 'should produce error message with tracing info' , function ( ) {
99104 assert . throws (
100- ( ) => evaluate ( { a : { b : 'c' } } , '1' ) ,
105+ ( ) => evaluate ( { a : { b : 'c' } } , '1' , { trace : true } ) ,
101106 JSONPointerEvaluateError ,
102- 'Invalid JSON Pointer: "1". Syntax error at position 0' ,
107+ 'Invalid JSON Pointer: "1". Syntax error at position 0, expected "/" ' ,
103108 ) ;
104109 } ) ;
105110 } ) ;
111+
112+ specify ( 'should produce error message without tracking info #1' , function ( ) {
113+ assert . throws (
114+ ( ) => evaluate ( { a : { b : 'c' } } , '1' ) ,
115+ JSONPointerEvaluateError ,
116+ 'Invalid JSON Pointer: "1". Syntax error at position 0' ,
117+ ) ;
118+ } ) ;
119+
120+ specify ( 'should produce error message without tracking info #2' , function ( ) {
121+ assert . throws (
122+ ( ) => evaluate ( { a : { b : 'c' } } , '1' , { trace : false } ) ,
123+ JSONPointerEvaluateError ,
124+ 'Invalid JSON Pointer: "1". Syntax error at position 0' ,
125+ ) ;
126+ } ) ;
106127} ) ;
0 commit comments