Helpful error when query returns object or array

pull/4717/head
Matt Visnovsky 6 months ago
parent 82352910bf
commit e2e81091c3

@ -407,6 +407,9 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue
} }
try { try {
response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response; 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; let jsonQueryExpression;
switch (jsonPathOperator) { switch (jsonPathOperator) {
case ">": case ">":

@ -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. // If a JSON path is provided, pre-evaluate the data using it.
response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response; 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 // Perform the comparison logic using the chosen operator
let jsonQueryExpression; let jsonQueryExpression;
switch (jsonPathOperator) { switch (jsonPathOperator) {

Loading…
Cancel
Save