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

Switch to props #31

Closed passsy closed 8 months ago

passsy commented 9 months ago

Before

spot<Checkbox>().existsOnce().hasWidgetProp(
      prop: (widget) => widget.value,
      name: 'value',
      match: (value) => value.equals(true),
    );

After

spot<Checkbox>().existsOnce().hasWidgetProp(
      prop: widgetProp('value', (widget) => widget.value),
      match: (value) => value.equals(true),
    );

This gives the possibility to reuse properties across different calls:

final checkbox$value = widgetProp<Checkbox, bool?>('value', (widget) => widget.value);

await widgetTester.pumpWidget(checkedCheckbox);
spot<Checkbox>().existsOnce()
    .hasWidgetProp(checkbox$value, (value) => value.equals(true));

await widgetTester.pumpWidget(uncheckedCheckbox);
spot<Checkbox>().existsOnce()
    .hasWidgetProp(checkbox$value, (value) => value.equals(false));

Not a breaking change, because the previous hasWidgetProp has never been released