diff --git a/src/util.js b/src/util.js index fb77cc957..c0c6a6d2e 100644 --- a/src/util.js +++ b/src/util.js @@ -407,6 +407,9 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue } try { response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response; + if (typeof response === "object" || Array.isArray(response) || response instanceof Date || typeof response === "function") { + throw new Error(`The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value`); + } let jsonQueryExpression; switch (jsonPathOperator) { case ">": diff --git a/src/util.ts b/src/util.ts index 8c67090b0..24a03f582 100644 --- a/src/util.ts +++ b/src/util.ts @@ -667,6 +667,10 @@ export async function evaluateJsonQuery(data: any, jsonPath: string, jsonPathOpe // If a JSON path is provided, pre-evaluate the data using it. response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response; + if (typeof response === "object" || Array.isArray(response) || response instanceof Date || typeof response === "function") { + throw new Error(`The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value`); + } + // Perform the comparison logic using the chosen operator let jsonQueryExpression; switch (jsonPathOperator) {