@@ -54,4 +54,52 @@ describe('JSONPath - Callback', function () {
5454 jsonpath ( { json, path : '$.store.bicycle' , resultType : 'value' , wrap : false , callback} ) ;
5555 assert . deepEqual ( result , expected ) ;
5656 } ) ;
57+
58+ it ( 'Callback with `resultType`: "all"' , ( ) => {
59+ const expected = [
60+ 'value' ,
61+ {
62+ path : "$['store']['bicycle']" ,
63+ value : json . store . bicycle ,
64+ parent : json . store ,
65+ parentProperty : 'bicycle' ,
66+ pointer : '/store/bicycle' ,
67+ hasArrExpr : undefined
68+ } ,
69+ {
70+ path : "$['store']['bicycle']" ,
71+ value : json . store . bicycle ,
72+ parent : json . store ,
73+ parentProperty : 'bicycle' ,
74+ pointer : '/store/bicycle' ,
75+ hasArrExpr : undefined
76+ }
77+ ] ;
78+ let result ;
79+ /**
80+ *
81+ * @param {PlainObject } data
82+ * @param {string } type
83+ * @param {PlainObject } fullData
84+ * @returns {void }
85+ */
86+ function callback ( data , type , fullData ) {
87+ if ( ! result ) {
88+ result = [ ] ;
89+ }
90+ result . push ( type , data , fullData ) ;
91+ }
92+ jsonpath ( { json, path : '$.store.bicycle' , resultType : 'all' , wrap : false , callback} ) ;
93+ assert . deepEqual ( result [ 0 ] , expected [ 0 ] ) ;
94+ // Todo[chai@>=5]: Error with circular perhaps will be resolved per https://github.com/chaijs/chai/issues/1109#issuecomment-395980733
95+ // so can try directly comparing whole object (as commented out) rather
96+ // than in parts as below that
97+ // assert.deepEqual(result, expected);
98+ Object . keys ( result [ 1 ] ) . forEach ( ( prop ) => {
99+ assert . deepEqual ( result [ 1 ] [ prop ] , expected [ 1 ] [ prop ] ) ;
100+ } ) ;
101+ Object . keys ( result [ 2 ] ) . forEach ( ( prop ) => {
102+ assert . deepEqual ( result [ 2 ] [ prop ] , expected [ 2 ] [ prop ] ) ;
103+ } ) ;
104+ } ) ;
57105} ) ;
0 commit comments