karatelabs/karate · error · RuntimeException

expect().to.have.all - no such api:

Error message

expect().to.have.all - no such api: 

What it means

Unknown-API sentinel in Expect's initExpectToHaveAll: the expect().to.have.all 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.all. The input at fault is the unrecognized key string appended to the message, indicating a typo or unsupported .have.all sub-API.

Solutions

  1. Use expect(obj).to.have.all.keys(['a','b']) with the exact supported syntax
  2. Alternative: match obj == '{ a: #present, b: #present }' or match obj contains only ...
  3. Check the feature output for the exact offending key shown in the message

Example fix

// before
expect(obj).to.have.all.properties('a','b') // no such api: properties
// after
expect(obj).to.have.all.keys(['a','b'])
Defensive patterns

Strategy: validation

Validate before calling

if (key !== 'keys') throw 'only .to.have.all.keys is supported, got: ' + key;

Type guard

function isMap(v){ return v != null && typeof v === 'object' && !(v instanceof Array); }

Try / catch

try { expect(obj).to.have.all.keys(['a','b']); } catch (e) { karate.log(e.message); }

Prevention

When it happens

Trigger: expect(obj).to.have.all.<key>(...) with an unsupported key, e.g. expect(obj).to.have.all.properties(...) instead of keys, or typos.

Common situations: Chai's .to.have.all.keys ported incorrectly with an extra word or misspelling (propties, fields).

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


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/bc6952260ac3d1b8. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/match/Expect.java:344

            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);
        };
    }

    @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);
        };

View on GitHub (pinned to a22eb90246)