{"record":{"id":"cbef178e4889f25d","repo":"karatelabs/karate","slug":"expect-no-such-api","errorCode":null,"errorMessage":"expect() - no such api: ","messagePattern":"expect\\(\\) - no such api: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/match/Expect.java","lineNumber":518,"sourceCode":"        if (\"not\".equals(key)) {\n            return new Expect(subject, true, onResult, throwOnFailure, contextSupplier);\n        }\n        if (\"that\".equals(key) || \"and\".equals(key) || \"which\".equals(key)) {\n            return this; // language chains\n        }\n        if (\"be\".equals(key) || \"is\".equals(key)) {\n            return expectToBe; // shorthand for .to.be\n        }\n        if (\"have\".equals(key) || \"has\".equals(key)) {\n            return expectToHave; // shorthand for .to.have\n        }\n        if (\"include\".equals(key) || \"contain\".equals(key)) {\n            return matchChainable(Match.Type.CONTAINS); // shorthand for .to.include / .to.contain\n        }\n        if (\"equal\".equals(key) || \"eql\".equals(key)) {\n            return match(Match.Type.EQUALS); // shorthand for .to.equal / .to.eql\n        }\n        throw new RuntimeException(\"expect() - no such api: \" + key);\n    }\n\n    // ========== Getters for Composition ==========\n\n    public Object getSubject() {\n        return subject;\n    }\n\n    public boolean isNegated() {\n        return negated;\n    }\n\n    public BiConsumer<Context, Result> getOnResult() {\n        return onResult;\n    }\n\n    public boolean isThrowOnFailure() {\n        return throwOnFailure;","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/match/Expect.java#L500-L536","documentation":"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.","triggerScenarios":"Accessing an unknown member on expect(...), e.g. expect(x).length, expect(x).ok, expect(x).toThrow, or a typo like expect(x).eqls(...).","commonSituations":"Chai's property-style assertions (.ok, .true, .empty) accessed directly; typos; assuming expect() returns the raw subject instead of an assertion object.","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"],"exampleFix":"// before\nexpect(x).eql({ a: 1 }) // no such api: eqls? — use supported chain\n// after\nexpect(x).to.eql({ a: 1 })","handlingStrategy":"type-guard","validationCode":"// before chaining, verify the member is one of the Expect accessors\nvar expectKeys = ['to','not','that','and','which','be','is','have','has','include','contain','equal','eql'];\nif (expectKeys.indexOf(key) < 0) throw 'unsupported expect() member: ' + key;","typeGuard":"function isExpect(o){ return o != null && o.getSubject !== undefined; } // check subject access before raw property reads","tryCatchPattern":"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; }","preventionTips":["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"],"tags":["expect","unsupported-key","property-access"],"backgroundTag":"invalid-enum-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}