passsy / spot

Chainable powerful Flutter widget selector API, screenshots and assertions for awesome widget tests.
https://pub.dev/packages/spot
Apache License 2.0
62 stars 1 forks source link

hasProp(widgetSelector: ) can't check for properties #33

Closed passsy closed 8 months ago

passsy commented 8 months ago

I want to check if TronButton.onTap is set or not.

Old API (0.6.0)

extension EffectiveTextMatcher on WidgetMatcher<TronButton> {
  // ignore: avoid_positional_boolean_parameters
  WidgetMatcher<TronButton> isTappable(bool value) {
    return hasProp(
      selector: (subject) => subject.context.nest<bool>(
        () => ['is clickable"'],
        (Element element) {
          final widget = element.widget as TronButton;
          return Extracted.value(widget.onTap != null);
        },
      ),
      match: (it) => it.equals(value),
    );
  }
}

Still not great with hasProp(widgetSelector: ) (spot 0.7.0)

extension EffectiveTextMatcher on WidgetMatcher<TronButton> {
  // ignore: avoid_positional_boolean_parameters
  WidgetMatcher<TronButton> isTappable(bool value) {
    return hasProp(
      widgetSelector: (w) => w.has((it) => it.onTap != null, 'isTappable'),
      match: (it) => it.equals(value),
    );
  }
}

Can we improve this?

passsy commented 8 months ago

Yes, use hasWidgetProp

extension EffectiveTextMatcher on WidgetMatcher<TronButton> {
  // ignore: avoid_positional_boolean_parameters
  WidgetMatcher<TronButton> isTappable(bool value) {
    return hasWidgetProp(
      prop: widgetProp('isTappable', (w) => w.onTap != null),
      match: (it) => it.equals(value),
    );
  }
}