hoppscotch/hoppscotch · error · Error

Expected value at path '${path}' to be '${expectedValue}', b

Error message

Expected value at path '${path}' to be '${expectedValue}', but got '${actualValue}'

What it means

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.

Source

Thrown at packages/hoppscotch-js-sandbox/src/cage-modules/utils/chai-helpers.ts:2250

                const pathStr = String(path).replace(/^\$\.?/, "")
                const segments = pathStr.split(/\.|\[/).filter(Boolean)
                const lastSegment = segments[segments.length - 1]?.replace(
                  /\]$/,
                  ""
                )

                // Check if it's an array index
                if (lastSegment && /^\d+$/.test(lastSegment)) {
                  errorMessage = `Array index '${lastSegment}' out of bounds`
                } else {
                  errorMessage = `Property '${lastSegment || pathStr}' not found`
                }
              } else if (expectedValue !== undefined) {
                errorMessage = `Expected value at path '${path}' to be '${expectedValue}', but got '${actualValue}'`
              } else {
                errorMessage = `JSONPath assertion failed for '${path}'`
              }
              throw new Error(errorMessage)
            }
          },
          buildMessage(value, mods, "jsonPath", args)
        )
      }
    ),

    // expect.fail() - Force a test failure
    // Supports multiple signatures:
    // expect.fail()
    // expect.fail(message)
    // expect.fail(actual, expected)
    // expect.fail(actual, expected, message)
    // expect.fail(actual, expected, message, operator)
    chaiFail: defineSandboxFn(ctx, "chaiFail", (...args: unknown[]) => {
      const targetTest = getCurrentTest()
      if (!targetTest) return

View on GitHub (pinned to 1acb8a3a75)

Solutions

  1. Log the actual value at the path before asserting: console.log(response.status) to see what the API returned.
  2. If the value type differs (string vs. number), coerce to match or update the expected value type.
  3. If the value is correct but you used .not, remove negation — this error means the values genuinely differ.
  4. Update the expected value to match the current API contract, or fix the test setup so the API returns the expected state.

Example fix

// before
expect(response).to.have.jsonPath('$.statusCode', 200)

// after — the API returns a string, not a number
console.log(typeof response.statusCode) // 'string'
expect(response).to.have.jsonPath('$.statusCode', '200')
Defensive patterns

Strategy: validation

Validate before calling

// Resolve the path and compare types before asserting equality
function resolvePath(data, pathStr) {
  const segments = pathStr.replace(/^\$\.?/, '').split(/\.|\[/).map(s => s.replace(/\]$/, '')).filter(Boolean)
  let current = data
  for (const seg of segments) {
    if (current == null) return undefined
    current = current[seg]
  }
  return current
}

const actual = resolvePath(response, '$.statusCode')
console.log('Actual value:', actual, 'Type:', typeof actual)
if (actual !== undefined) {
  expect(response).to.have.jsonPath('$.statusCode', '200')
}

Type guard

function pathValueMatchesType(data, pathStr, expected) {
  const actual = resolvePath(data, pathStr)
  if (actual === undefined) return false
  return typeof actual === typeof expected || String(actual) === String(expected)
}

Try / catch

try {
  expect(response).to.have.jsonPath('$.status', 'active')
} catch (e) {
  if (e.message.includes('but got')) {
    const actual = resolvePath(response, '$.status')
    console.error('Expected: active, Actual:', actual, 'Type:', typeof actual)
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hoppscotch/hoppscotch@1acb8a3a75 (2026-08-12). Data as JSON: /api/errors/fdbf4c5dfdf56728. Report an issue: GitHub.