Package io.karatelabs.match
Class Expect
java.lang.Object
io.karatelabs.match.Expect
- All Implemented Interfaces:
io.karatelabs.js.ObjectLike,io.karatelabs.js.SimpleObject
Chai-style BDD assertion API for Karate.
Usage:
karate.expect(actual).to.equal(expected)
karate.expect(actual).to.be.a('string')
karate.expect(actual).to.have.property('name')
karate.expect(actual).to.not.equal(unexpected)
-
Field Summary
Fields inherited from interface io.karatelabs.js.SimpleObject
logger, TO_STRING -
Constructor Summary
ConstructorsConstructorDescriptionExpect(Object subject, boolean negated, BiConsumer<io.karatelabs.js.Context, Result> onResult, boolean throwOnFailure) Creates an Expect instance with control over throw behavior.Expect(Object subject, boolean negated, BiConsumer<io.karatelabs.js.Context, Result> onResult, boolean throwOnFailure, Supplier<io.karatelabs.js.Context> contextSupplier) Creates an Expect instance with full control over behavior.Expect(Object subject, BiConsumer<io.karatelabs.js.Context, Result> onResult) -
Method Summary
Modifier and TypeMethodDescriptionSupplier<io.karatelabs.js.Context> BiConsumer<io.karatelabs.js.Context, Result> static StringgetSourceFromContext(io.karatelabs.js.Context context) Extracts the source expression from the JS Context AST.booleanbooleanMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.karatelabs.js.ObjectLike
getMember, getPrototype, isExtensible, isFrozen, isOwnProperty, isSealed, putMember, removeMember, setExtensible, setFrozen, setSealedMethods inherited from interface io.karatelabs.js.SimpleObject
getMember, jsKeys, jsToString, putMember, removeMember, toMap
-
Constructor Details
-
Expect
-
Expect
-
Expect
public Expect(Object subject, boolean negated, BiConsumer<io.karatelabs.js.Context, Result> onResult, boolean throwOnFailure) Creates an Expect instance with control over throw behavior.- Parameters:
subject- the value to make assertions onnegated- whether assertions should be negatedonResult- callback for handling assertion results (can be null)throwOnFailure- if true, throws AssertionError on failures; if false, only calls onResult
-
Expect
public Expect(Object subject, boolean negated, BiConsumer<io.karatelabs.js.Context, Result> onResult, boolean throwOnFailure, Supplier<io.karatelabs.js.Context> contextSupplier) Creates an Expect instance with full control over behavior.- Parameters:
subject- the value to make assertions onnegated- whether assertions should be negatedonResult- callback for handling assertion results (can be null)throwOnFailure- if true, throws AssertionError on failures; if false, only calls onResultcontextSupplier- optional supplier for getting a context when none is available (e.g., for property-style assertions)
-
-
Method Details
-
getSourceFromContext
Extracts the source expression from the JS Context AST. Used for including the original expression in error messages. -
jsGet
- Specified by:
jsGetin interfaceio.karatelabs.js.SimpleObject
-
getSubject
-
isNegated
public boolean isNegated() -
getOnResult
-
isThrowOnFailure
public boolean isThrowOnFailure() -
getContextSupplier
-