karatelabs/karate · error · RuntimeException
expect() - no such api:
Error message
expect() - no such api:
What it means
The base Expect object exposes only its whitelisted property keys (to, not, that/and/which, be/is, have/has, include/contain, equal/eql). Any other property access on an expect() result throws a RuntimeException naming the key.
Solutions
- Chain only through supported keys: to/not/and/that/which/be/have/include/contain/equal/eql
- Extract the subject for raw checks: expect(x).subject or use plain JS/Java comparisons
- Fix typos in chained keys
Example fix
// before
expect(x).eql({ a: 1 }) // no such api: eqls? — use supported chain
// after
expect(x).to.eql({ a: 1 }) Defensive patterns
Strategy: type-guard
Validate before calling
// before chaining, verify the member is one of the Expect accessors var expectKeys = ['to','not','that','and','which','be','is','have','has','include','contain','equal','eql']; if (expectKeys.indexOf(key) < 0) throw 'unsupported expect() member: ' + key;
Type guard
function isExpect(o){ return o != null && o.getSubject !== undefined; } // check subject access before raw property reads Try / catch
try { expect(x).to.equal(y); } catch (e) { if (e.message.indexOf('no such api') >= 0) karate.log('typo in expect chain: ' + e.message); else throw e; } Prevention
- Never access arbitrary properties on expect() results — it is an assertion object, not the subject
- Use .getSubject()/expect(x).subject if the raw value is needed
- Fix typos like eqls/equls; the exact bad key is printed in the message
When it happens
Trigger: Accessing an unknown member on expect(...), e.g. expect(x).length, expect(x).ok, expect(x).toThrow, or a typo like expect(x).eqls(...).
Common situations: Chai's property-style assertions (.ok, .true, .empty) accessed directly; typos; assuming expect() returns the raw subject instead of an assertion object.
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.deep - no such api
- expect().to.have.all - no such api:
- expect().to.have.any - no such api:
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/cbef178e4889f25d.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/match/Expect.java:518
if ("not".equals(key)) {
return new Expect(subject, true, onResult, throwOnFailure, contextSupplier);
}
if ("that".equals(key) || "and".equals(key) || "which".equals(key)) {
return this; // language chains
}
if ("be".equals(key) || "is".equals(key)) {
return expectToBe; // shorthand for .to.be
}
if ("have".equals(key) || "has".equals(key)) {
return expectToHave; // shorthand for .to.have
}
if ("include".equals(key) || "contain".equals(key)) {
return matchChainable(Match.Type.CONTAINS); // shorthand for .to.include / .to.contain
}
if ("equal".equals(key) || "eql".equals(key)) {
return match(Match.Type.EQUALS); // shorthand for .to.equal / .to.eql
}
throw new RuntimeException("expect() - no such api: " + key);
}
// ========== Getters for Composition ==========
public Object getSubject() {
return subject;
}
public boolean isNegated() {
return negated;
}
public BiConsumer<Context, Result> getOnResult() {
return onResult;
}
public boolean isThrowOnFailure() {
return throwOnFailure;View on GitHub (pinned to a22eb90246)