karatelabs/karate · error · RuntimeException
expect().to.deep - no such api
Error message
expect().to.deep - no such api: ${key} What it means
Unknown-API guard in the expect().to.deep chain: the chained property name after .deep is not one of the supported deep-match APIs (e.g. include). Fires on a typo or unsupported key in the chai-like expect DSL; message interpolates the bad key.
Solutions
- Use expect(obj).to.include(expected) for deep containment
- Use expect(obj).to.equal(expected) for full deep equality — Karate's equals is already deep
- Use match == for full structural comparison
Example fix
// before expect(response).to.deep.equal(expected) // no such api: equal // after expect(response).to.equal(expected)
Defensive patterns
Strategy: validation
Validate before calling
if (key !== 'include') throw 'only .to.deep.include is supported, got: ' + key;
Try / catch
try { expect(obj).to.deep.include(expected); } catch (e) { karate.log(e.message); } Prevention
- Remember: Karate's .to.equal is already deep equality — no .deep.equal needed
- Use .to.deep.include for deep partial containment
- Avoid transplanting Chai's .deep modifier onto other verbs
When it happens
Trigger: expect(obj).to.deep.<key>(...) with key != 'include', e.g. expect(obj).to.deep.equal(...) or .to.deep.contain.
Common situations: Chai habits where .deep.equal exists; in Karate plain .to.equal already does deep equality so .to.deep.equal is unnecessary and invalid.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- expect().to.be.at - no such api
- expect().to.be - no such api
- expect().to.have.all - no such api:
- expect().to.have.any - no such api:
- expect().to.have.nested - no such api:
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/7398d53720642c60.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/match/Expect.java:327
Number delta = (Number) args[1];
Result result;
if (Math.abs(actual.doubleValue() - expected.doubleValue()) <= delta.doubleValue()) {
result = Result.PASS;
} else {
result = Result.fail(actual + " not close to " + expected + " ± " + delta);
}
handleResult(context, result);
return new Expect(subject, false, onResult, throwOnFailure, contextSupplier);
};
case "at" -> expectToBeAt;
default -> throw new RuntimeException("expect().to.be - no such api: " + key);
};
}
private SimpleObject initExpectToDeep() {
return key -> switch (key) {
case "include" -> match(Match.Type.CONTAINS_DEEP);
default -> throw new RuntimeException("expect().to.deep - no such api: " + key);
};
}
@SuppressWarnings("unchecked")
private SimpleObject initExpectToHaveAll() {
return key -> switch (key) {
case "keys" -> (JavaCallable) (context, args) -> {
Result result;
if (subject instanceof Map<?, ?> map) {
result = evaluate(map.keySet(), Match.Type.CONTAINS, args[0]);
} else {
result = Result.fail("not an object");
}
handleResult(context, result);
return new Expect(subject, false, onResult, throwOnFailure, contextSupplier);
};
default -> throw new RuntimeException("expect().to.have.all - no such api: " + key);
};View on GitHub (pinned to a22eb90246)