self-assert / RuleEvaluation
Class: RuleEvaluation<PredicateReturnType, ValueType>
Represents the evaluation of a rule on a given value.
It can also be created using the Rule.evaluateFor method.
Example
const nameNotBlank = Assertion.requiring(
"customer.name.notBlank",
"Name must not be blank",
Requirements.isNotBlank
);
const evaluation = nameNotBlank.evaluateFor("John");
console.log(evaluation.doesHold()); // true
/**
* Or use RuleEvaluation directly
*/
const evaluation = new RuleEvaluation(nameNotBlank, "John");
console.log(evaluation.doesHold()); // trueType Parameters
| Type Parameter | Description |
|---|---|
PredicateReturnType extends MaybeAsync<boolean> | - |
ValueType | The type of value the rule applies to. |
Implements
CollectableRule<void,PredicateReturnTypeextendsboolean?void:Promise<void>>
Constructors
Constructor
new RuleEvaluation<
PredicateReturnType,ValueType>(rule,value):RuleEvaluation<PredicateReturnType,ValueType>
Parameters
| Parameter | Type |
|---|---|
rule | Rule<PredicateReturnType, ValueType> |
value | ValueType |
Returns
RuleEvaluation<PredicateReturnType, ValueType>
Rule evaluation
doesHold()
doesHold():
PredicateReturnType
Returns
PredicateReturnType
See
hasFailed()
hasFailed():
PredicateReturnType
Returns
PredicateReturnType
See
mustHold()
mustHold():
PredicateReturnTypeextendsboolean?void:Promise<void>
Returns
PredicateReturnType extends boolean ? void : Promise<void>
See
collectFailureInto()
collectFailureInto(
failed):PredicateReturnTypeextendsboolean?void:Promise<void>
Parameters
| Parameter | Type |
|---|---|
failed | LabeledRule[] |
Returns
PredicateReturnType extends boolean ? void : Promise<void>
See
Implementation of
CollectableRule.collectFailureInto
Labeling
isLabeledAs()
isLabeledAs(
aBrokenRuleLabel):boolean
Checks if the assertion has the same id and description as the given one.
Parameters
| Parameter | Type |
|---|---|
aBrokenRuleLabel | LabeledRule |
Returns
boolean
Implementation of
hasLabel()
hasLabel(
anId,aDescription):boolean
Compare the id and description of the assertion with the given ones.
Parameters
| Parameter | Type |
|---|---|
anId | string |
aDescription | string |
Returns
boolean
Implementation of
hasDescription()
hasDescription(
aDescription):boolean
Checks if the assertion has the given description.
Parameters
| Parameter | Type |
|---|---|
aDescription | string |
Returns
boolean
Remarks
This method is used mostly for testing.
Implementation of
CollectableRule.hasDescription
hasLabelId()
hasLabelId(
anId):boolean
Compares the id of the assertion with the given one.
Parameters
| Parameter | Type |
|---|---|
anId | string |
Returns
boolean
Implementation of
getId()
getId():
string
Returns the label identifier.
Returns
string
Implementation of
getDescription()
getDescription():
string
Returns
string
