karatelabs/karate · error · RuntimeException

expect().to.be.at - no such api

Error message

expect().to.be.at - no such api: ${key}

What it means

The expect().to.be.at sub-API only supports comparison keys such as 'least' (>=) and 'most' (<=). An unknown key passed after .to.be.at makes initExpectToBeAt throw a RuntimeException naming the unsupported key.

Solutions

  1. Use the supported keys: expect(x).to.be.at.least(n) / .at.most(n)
  2. For strict comparisons use .to.be.above/.below equivalents or plain match syntax: match x == '#(_ > 6)'
  3. Check docs for the exact expect() BDD keyword list

Example fix

// before
expect(5).to.be.at.above(4) // no such api: above
// after
expect(5).to.be.at.least(5)
Defensive patterns

Strategy: validation

Validate before calling

// only 'least' and 'most' are valid after .to.be.at
var validAtKeys = ['least', 'most'];
karate.match('at-key', key, '#(validAtKeys.includes(key) ? "#string" : "#notpresent")')
// simpler: assert before using
if (!validAtKeys.includes(key)) throw 'unsupported .to.be.at key: ' + key;

Try / catch

try { expect(n).to.be.at.least(5); } catch (e) { karate.log('unsupported key: ' + e.message); }

Prevention

When it happens

Trigger: Calling expect(x).to.be.at.<key>(...) with a key not handled by the switch (anything other than the supported comparison keys like least/most), e.g. expect(5).to.be.at.greater(6) or a Chai-style key that Karate does not implement.

Common situations: Porting Chai.js assertions (e.g. above/below) to Karate without checking Karate's keyword set; typos like 'leat' or 'mos'; assuming richer Chai vocabulary exists.

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/d6c2d0791747af22. Report an issue: GitHub.

Appendix: source

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

    // ========== Chain Initializers ==========

    private SimpleObject initExpectToBeAt() {
        return key -> switch (key) {
            case "least" -> handle(rhs -> {
                if (subject instanceof Number actual && rhs instanceof Number expected) {
                    return actual.doubleValue() >= expected.doubleValue() ? null : subject + " is not at least: " + rhs;
                } else {
                    return subject + " is not at least: " + rhs;
                }
            });
            case "most" -> handle(rhs -> {
                if (subject instanceof Number actual && rhs instanceof Number expected) {
                    return actual.doubleValue() <= expected.doubleValue() ? null : subject + " is not at most: " + rhs;
                } else {
                    return subject + " is not at most: " + rhs;
                }
            });
            default -> throw new RuntimeException("expect().to.be.at - no such api: " + key);
        };
    }

    @SuppressWarnings("unchecked")
    private SimpleObject initExpectToBe() {
        return key -> switch (key) {
            case "not" -> new Expect(subject, !negated, onResult, throwOnFailure, contextSupplier).expectToBe;
            case "that", "and", "which" -> this;
            case "a", "an" -> handleChainable(rhs -> {
                String expected = rhs + "";
                String actual;
                if (subject instanceof List) {
                    actual = "array";
                } else {
                    actual = Terms.typeOf(subject);
                }
                return expected.equals(actual) ? null : "actual: " + actual + ", expected: " + expected;
            });

View on GitHub (pinned to a22eb90246)