Skip to content

Commit

Permalink
Add missing @useResult to QuantitySelectors
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Nov 25, 2024
1 parent a334e0e commit 2eb5f7b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void main() {
spot<Text>().withText('c').doesNotExist();
spot<Text>().withText('c').overrideWidgetPresence(WidgetPresence.offstage).existsOnce();
spotOffstage().spot<Text>().atMost(3);
spotOffstage().spot<Text>().existsAtMostNTimes(3);
spotOffstage().spotText('c').existsOnce();
spotOffstage().overrideWidgetPresence(WidgetPresence.onstage).spotText('c').doesNotExist();
Expand Down
4 changes: 4 additions & 0 deletions lib/src/spot/selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -721,16 +721,19 @@ extension ReadSingleSnapshot<W extends Widget> on WidgetSelector<W> {
/// selection of widgets.
extension QuantitySelectors<W extends Widget> on WidgetSelector<W> {
/// Sets the selector to match exactly [n] widgets.
@useResult
WidgetSelector<W> amount(int n) {
return self.overrideQuantityConstraint(QuantityConstraint.exactly(n));
}

/// Sets the selector to match at least [n] widgets.
@useResult
WidgetSelector<W> atLeast(int n) {
return self.overrideQuantityConstraint(QuantityConstraint.atLeast(n));
}

/// Sets the selector to match at most [n] widgets.
@useResult
WidgetSelector<W> atMost(int n) {
return self.overrideQuantityConstraint(QuantityConstraint.atMost(n));
}
Expand All @@ -739,6 +742,7 @@ extension QuantitySelectors<W extends Widget> on WidgetSelector<W> {
///
/// This method allows for more flexible control over the number of widgets
/// the selector should match.
@useResult
WidgetSelector<W> overrideQuantityConstraint(QuantityConstraint constraint) {
return self.copyWith(quantityConstraint: constraint);
}
Expand Down
10 changes: 5 additions & 5 deletions test/selectors/filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void main() {
),
);

spot<Text>().atMost(2);
spot<Text>().existsAtMostNTimes(2);
spotText('c').doesNotExist();
});

Expand All @@ -160,11 +160,11 @@ void main() {
),
);

spot<Text>().atMost(2);
spot<Text>().existsAtMostNTimes(2);
spotText('a').existsExactlyNTimes(1);
spotText('c').doesNotExist();

spotOffstage().spot<Text>().atMost(1);
spotOffstage().spot<Text>().existsAtMostNTimes(1);
spotOffstage().spotText('a').doesNotExist();
spotOffstage().spotText('c').existsOnce();
});
Expand All @@ -184,7 +184,7 @@ void main() {
),
);

spotOffstage().spot<Text>().atMost(3);
spotOffstage().spot<Text>().existsAtMostNTimes(3);
spotOffstage().spotText('a').doesNotExist();
spotOffstage().spotText('c').existsOnce();
spotOffstage()
Expand Down Expand Up @@ -253,7 +253,7 @@ void main() {
),
);

spotAllWidgets().spot<Text>().atMost(3);
spotAllWidgets().spot<Text>().existsAtMostNTimes(3);
spotAllWidgets().spotText('a').existsOnce();
spotAllWidgets().spotText('c').existsOnce();
spotAllWidgets()
Expand Down

0 comments on commit 2eb5f7b

Please sign in to comment.