hasElementProp<T> method
WidgetMatcher<W>
hasElementProp<T>({
- required NamedElementProp<
T?> prop, - required MatchProp<
T> match,
Asserts that an element's property meets a specific condition.
This method is useful for making assertions on properties within the element of the widget.
Example usage:
spot<Checkbox>().existsOnce().hasElementProp(
prop: elementProp('value', (e) => (e.widget as Checkbox).value),
match: (it) => it.equals(true),
);
Implementation
WidgetMatcher<W> hasElementProp<T>({
required NamedElementProp<T?> prop,
required MatchProp<T> match,
}) {
void condition(Subject<Element> subject) {
final Subject<T> value = subject.context.nest<T?>(
() => ['Element of $W', "with prop '${prop.name}'"],
(element) {
final value = getElementProp(prop);
return Extracted.value(value);
},
).hideNullability();
match(value);
}
final failure = softCheckHideNull(element, condition);
failure.throwPropertyCheckFailure(condition, element);
return this;
}