Skip to content

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 ​

ts
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()); // true

Type Parameters ​

Type ParameterDescription
PredicateReturnType extends MaybeAsync<boolean>-
ValueTypeThe type of value the rule applies to.

Implements ​

  • CollectableRule<void, PredicateReturnType extends boolean ? void : Promise<void>>

Constructors ​

Constructor ​

new RuleEvaluation<PredicateReturnType, ValueType>(rule, value): RuleEvaluation<PredicateReturnType, ValueType>

Parameters ​

ParameterType
ruleRule<PredicateReturnType, ValueType>
valueValueType

Returns ​

RuleEvaluation<PredicateReturnType, ValueType>

Rule evaluation ​

doesHold() ​

doesHold(): PredicateReturnType

Returns ​

PredicateReturnType

See ​

Rule.doesHold


hasFailed() ​

hasFailed(): PredicateReturnType

Returns ​

PredicateReturnType

See ​

Rule.hasFailed


mustHold() ​

mustHold(): PredicateReturnType extends boolean ? void : Promise<void>

Returns ​

PredicateReturnType extends boolean ? void : Promise<void>

See ​

Rule.mustHold


collectFailureInto() ​

collectFailureInto(failed): PredicateReturnType extends boolean ? void : Promise<void>

Parameters ​

ParameterType
failedLabeledRule[]

Returns ​

PredicateReturnType extends boolean ? void : Promise<void>

See ​

Rule.collectFailureInto

Implementation of ​

CollectableRule.collectFailureInto

Labeling ​

isLabeledAs() ​

isLabeledAs(aBrokenRuleLabel): boolean

Checks if the assertion has the same id and description as the given one.

Parameters ​

ParameterType
aBrokenRuleLabelLabeledRule

Returns ​

boolean

Implementation of ​

CollectableRule.isLabeledAs


hasLabel() ​

hasLabel(anId, aDescription): boolean

Compare the id and description of the assertion with the given ones.

Parameters ​

ParameterType
anIdstring
aDescriptionstring

Returns ​

boolean

Implementation of ​

CollectableRule.hasLabel


hasDescription() ​

hasDescription(aDescription): boolean

Checks if the assertion has the given description.

Parameters ​

ParameterType
aDescriptionstring

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 ​

ParameterType
anIdstring

Returns ​

boolean

Implementation of ​

CollectableRule.hasLabelId


getId() ​

getId(): string

Returns the label identifier.

Returns ​

string

Implementation of ​

CollectableRule.getId


getDescription() ​

getDescription(): string

Returns ​

string

Implementation of ​

CollectableRule.getDescription