{"record":{"id":"65cc65739db308d5","repo":"karatelabs/karate","slug":"expect-to-be-no-such-api-key","errorCode":null,"errorMessage":"expect().to.be - no such api: ${key}","messagePattern":"expect\\(\\)\\.to\\.be - no such api: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/match/Expect.java","lineNumber":320,"sourceCode":"                }\n                handleResult(context, result);\n                return new Expect(subject, false, onResult, throwOnFailure, contextSupplier);\n            };\n            case \"closeTo\", \"approximately\" -> (JavaCallable) (context, args) -> {\n                Number actual = (Number) subject;\n                Number expected = (Number) args[0];\n                Number delta = (Number) args[1];\n                Result result;\n                if (Math.abs(actual.doubleValue() - expected.doubleValue()) <= delta.doubleValue()) {\n                    result = Result.PASS;\n                } else {\n                    result = Result.fail(actual + \" not close to \" + expected + \" ± \" + delta);\n                }\n                handleResult(context, result);\n                return new Expect(subject, false, onResult, throwOnFailure, contextSupplier);\n            };\n            case \"at\" -> expectToBeAt;\n            default -> throw new RuntimeException(\"expect().to.be - no such api: \" + key);\n        };\n    }\n\n    private SimpleObject initExpectToDeep() {\n        return key -> switch (key) {\n            case \"include\" -> match(Match.Type.CONTAINS_DEEP);\n            default -> throw new RuntimeException(\"expect().to.deep - no such api: \" + key);\n        };\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private SimpleObject initExpectToHaveAll() {\n        return key -> switch (key) {\n            case \"keys\" -> (JavaCallable) (context, args) -> {\n                Result result;\n                if (subject instanceof Map<?, ?> map) {\n                    result = evaluate(map.keySet(), Match.Type.CONTAINS, args[0]);\n                } else {","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/match/Expect.java#L302-L338","documentation":"The expect().to.be API supports a fixed set of keys (exist, a/an style checks, closeTo, at, etc.). Any other key passed after .to.be makes initExpectToBe throw a RuntimeException naming the unknown key.","triggerScenarios":"expect(x).to.be.<key>(...) with a key outside the switch cases, e.g. expect(x).to.be.true (booleans handled differently), .to.be.ok, .to.be.null, or any typo.","commonSituations":"Copying Chai.js idioms (.to.be.true, .to.be.null, .to.be.empty) into Karate; typos like 'exits' instead of 'exist'.","solutions":["Replace with Karate-native equivalents: expect(x == true), match x == '#null', expect(x).to.exist for existence","Use match (== '#(notnull)', '#present') for type/null checks","Verify the key against the supported expect() keyword list in docs"],"exampleFix":"// before\nexpect(flag).to.be.true // no such api: true\n// after\nexpect(flag == true)","handlingStrategy":"validation","validationCode":"// before expect(x).to.be.<key>, confirm key is supported: exist, a/an-type checks, closeTo, at\nvar beKeys = ['exist','closeTo','at'];\nif (beKeys.indexOf(key) < 0) throw 'unsupported .to.be key: ' + key;","typeGuard":"function isBoolean(v){ return typeof v === 'boolean'; } // use expect(isBoolean(flag) && flag) instead of .to.be.true","tryCatchPattern":"try { expect(val).to.be.closeTo(10, 0.5); } catch (e) { karate.log(e.message); }","preventionTips":["Replace .to.be.true/.to.be.false/.to.be.null with explicit JS boolean expressions","Use match x == '#null' / '#notnull' for null checks","Keep a cheat-sheet mapping Chai idioms to Karate equivalents"],"tags":["expect","unsupported-key","bdd-assertion"],"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-16T19:17:19.609Z"}