karatelabs/karate · error · RuntimeException
expect().to.have.any - no such api:
Error message
expect().to.have.any - no such api:
What it means
Unknown-API sentinel in Expect's initExpectToHaveAny: the expect().to.have.any accessor is a switch over API key names (e.g. keys), and this fires when a property not in the switch is accessed after expect(...).to.have.any. The input at fault is the unrecognized key string appended to the message, indicating a typo or unsupported .have.any sub-API.
Solutions
- Use expect(obj).to.have.any.keys(['a','b']) exactly
- Or use match syntax: match obj contains { a: '#present' }
- Cross-check the keyword list; message prints the exact bad key
Example fix
// before expect(obj).to.have.any.of(['a','b']) // no such api: of // after expect(obj).to.have.any.keys(['a','b'])
Defensive patterns
Strategy: validation
Validate before calling
if (key !== 'keys') throw 'only .to.have.any.keys is supported, got: ' + key;
Try / catch
try { expect(obj).to.have.any.keys(['a','b']); } catch (e) { karate.log(e.message); } Prevention
- Use .to.have.any.keys(...) exactly; drop Chai's .of/.oneOf modifiers
- Alternative: match obj contains { a: '#present' } for single-key checks
When it happens
Trigger: expect(obj).to.have.any.<key>(...) with a key other than the supported one, e.g. .to.have.any.of(...) or .to.have.any.properties(...).
Common situations: Chai's .to.have.any.keys idiom mistyped as of/property; mixing Mocha/Chai vocabulary into Karate scripts.
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.have.all - no such api:
- expect().to.be.at - no such api
- expect().to.be - no such api
- expect().to.deep - 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/41779ae6c3219256.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/match/Expect.java:361
};
default -> throw new RuntimeException("expect().to.have.all - no such api: " + key);
};
}
@SuppressWarnings("unchecked")
private SimpleObject initExpectToHaveAny() {
return key -> switch (key) {
case "keys" -> (JavaCallable) (context, args) -> {
Result result;
if (subject instanceof Map<?, ?> map) {
result = evaluate(map.keySet(), Match.Type.CONTAINS_ANY, 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.any - no such api: " + key);
};
}
private SimpleObject initExpectToHaveNested() {
return key -> {
if ("property".equals(key)) {
return (JavaCallable) (context, args) -> {
String path = args[0] + "";
Json json;
try {
json = Json.of(subject);
} catch (Exception e) {
Result fail = Result.fail("expected to have property: " + path);
handleResult(context, fail);
return new Expect(subject, false, onResult, throwOnFailure, contextSupplier);
}
Result result;
if (args.length > 1) {View on GitHub (pinned to a22eb90246)