{"record":{"id":"fdbf4c5dfdf56728","repo":"hoppscotch/hoppscotch","slug":"expected-value-at-path-path-to-be-expected","errorCode":null,"errorMessage":"Expected value at path '${path}' to be '${expectedValue}', but got '${actualValue}'","messagePattern":"Expected value at path '(.+?)' to be '(.+?)', but got '(.+?)'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/hoppscotch-js-sandbox/src/cage-modules/utils/chai-helpers.ts","lineNumber":2250,"sourceCode":"                const pathStr = String(path).replace(/^\\$\\.?/, \"\")\n                const segments = pathStr.split(/\\.|\\[/).filter(Boolean)\n                const lastSegment = segments[segments.length - 1]?.replace(\n                  /\\]$/,\n                  \"\"\n                )\n\n                // Check if it's an array index\n                if (lastSegment && /^\\d+$/.test(lastSegment)) {\n                  errorMessage = `Array index '${lastSegment}' out of bounds`\n                } else {\n                  errorMessage = `Property '${lastSegment || pathStr}' not found`\n                }\n              } else if (expectedValue !== undefined) {\n                errorMessage = `Expected value at path '${path}' to be '${expectedValue}', but got '${actualValue}'`\n              } else {\n                errorMessage = `JSONPath assertion failed for '${path}'`\n              }\n              throw new Error(errorMessage)\n            }\n          },\n          buildMessage(value, mods, \"jsonPath\", args)\n        )\n      }\n    ),\n\n    // expect.fail() - Force a test failure\n    // Supports multiple signatures:\n    // expect.fail()\n    // expect.fail(message)\n    // expect.fail(actual, expected)\n    // expect.fail(actual, expected, message)\n    // expect.fail(actual, expected, message, operator)\n    chaiFail: defineSandboxFn(ctx, \"chaiFail\", (...args: unknown[]) => {\n      const targetTest = getCurrentTest()\n      if (!targetTest) return\n","sourceCodeStart":2232,"sourceCodeEnd":2268,"githubUrl":"https://github.com/hoppscotch/hoppscotch/blob/1acb8a3a7581e4db32ba0d529170c4669a2e1053/packages/hoppscotch-js-sandbox/src/cage-modules/utils/chai-helpers.ts#L2232-L2268","documentation":"Thrown by the chaiJsonPath assertion when the JSONPath resolves to a value (not undefined) but that value does not equal the expectedValue argument. This is the branch for the three-argument form: expect(data).to.have.jsonPath('$.status', 'active') where the resolved value differs.","triggerScenarios":"Calling expect(data).to.have.jsonPath('$.status', 'active') when data.status is actually 'pending' or 'inactive'. The evaluatePath function successfully resolves the path to a non-undefined value, but the strict equality check (===) fails.","commonSituations":"The API returned a different value than the test expected (e.g., an async operation hasn't completed so status is 'pending' instead of 'active'), or the test was written against an outdated API contract. Also hit with type mismatches: expecting a number 200 but the response contains a string '200', since === does not coerce.","solutions":["Log the actual value at the path before asserting: console.log(response.status) to see what the API returned.","If the value type differs (string vs. number), coerce to match or update the expected value type.","If the value is correct but you used .not, remove negation — this error means the values genuinely differ.","Update the expected value to match the current API contract, or fix the test setup so the API returns the expected state."],"exampleFix":"// before\nexpect(response).to.have.jsonPath('$.statusCode', 200)\n\n// after — the API returns a string, not a number\nconsole.log(typeof response.statusCode) // 'string'\nexpect(response).to.have.jsonPath('$.statusCode', '200')","handlingStrategy":"validation","validationCode":"// Resolve the path and compare types before asserting equality\nfunction resolvePath(data, pathStr) {\n  const segments = pathStr.replace(/^\\$\\.?/, '').split(/\\.|\\[/).map(s => s.replace(/\\]$/, '')).filter(Boolean)\n  let current = data\n  for (const seg of segments) {\n    if (current == null) return undefined\n    current = current[seg]\n  }\n  return current\n}\n\nconst actual = resolvePath(response, '$.statusCode')\nconsole.log('Actual value:', actual, 'Type:', typeof actual)\nif (actual !== undefined) {\n  expect(response).to.have.jsonPath('$.statusCode', '200')\n}","typeGuard":"function pathValueMatchesType(data, pathStr, expected) {\n  const actual = resolvePath(data, pathStr)\n  if (actual === undefined) return false\n  return typeof actual === typeof expected || String(actual) === String(expected)\n}","tryCatchPattern":"try {\n  expect(response).to.have.jsonPath('$.status', 'active')\n} catch (e) {\n  if (e.message.includes('but got')) {\n    const actual = resolvePath(response, '$.status')\n    console.error('Expected: active, Actual:', actual, 'Type:', typeof actual)\n  }\n  throw e\n}","preventionTips":["Log the actual value and its type before asserting equality.","Be aware that === is used — string '200' does not equal number 200.","Coerce types explicitly if the API returns a different type than expected.","Update the expected value to match the current API contract."],"tags":["jsonpath","chai-assertion","value-mismatch","sandbox"],"backgroundTag":null,"analyzedSha":"1acb8a3a7581e4db32ba0d529170c4669a2e1053","analyzedAt":"2026-08-12T11:34:52.648Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}