-
Notifications
You must be signed in to change notification settings - Fork 0
Options
This page details some of the options available in the API.
Specifies how to locate a substring within a string.
Used in: contains
.
Requires that the string begin with the given substring.
Requires that the string end with the given substring.
(Default) Only requires that the string contain the given substring.
Specifies how to locate elements within an array.
Used in: hasElements
and its shared aliases, has
and hasAsserts
.
Only requires that the items in the expected array exist within the contextual value with no regard to relative position.
Requires that the contextual value begin with the expected elements, in order.
Requires that the contextual value end with the expected elements, in order.
Requires that the contextual value contain the expected values as a subsequence.
Specifies how to interpret property assertions.
Used in: has
, hasProperties
, hasAll
, hasElements
.
For any lambda property assertions, wrap the actual value in an Assert and pass that in as the first parameter. Nevertheless, if the return value of the lambda is a strict (===) true or false, then true is pass, false is fail. Other property assertion types function as normal.
Forces literal interpretation of property values, even if they are lambdas or regular expressions. Similar to deepEquals, but will only check defined properties, rather than failing when one is missing.
Tries to interpret assertion properties as a person might. If the property is a:
- Lambda - then either assume it will perform its own assertions, or use the boolean return value to determine pass/fail (true/false).
- RegExp - then, if the actual value is a string, check for a match. If its a regular expression, perform a strict equals (===) on their string representations. Otherwise, throw.
- Object - recursively match according to 1-4.
- All Else - perform a strict equals.
A lambda assertion should be of the form
(actualValue: any) => boolean | IFluentNode | void;
where actualValue is the current property's value, and IFluentNode is the return value of an assertion (lets the framework know you didn't intend a boolean assertion).
Assert(obj).has({
propFnA: p => p > 3, // a boolean assertion, true = pass
propFnB: p => Assert(p).isDefined(), // pass if propFnB is defined.
propFnC: p => Assert(p).isDefined() && false, // caution: this will always fail, even if defined
propStrRE: /something/, // passes if matches RegExp
propRERE: /something/, // passes if string representations match
propObj: { // passes if nested assertions pass
nestedProp: // ...
},
propOther: "any other value type" // passes, if strictly equal
});