expectStateAction function

void expectStateAction(
  1. String stateName,
  2. String action, {
  3. int? times,
})

Assert that a state action was fired to the given stateName.

Optionally verify the specific action name and number of times.

Example:

fireStateAction('MyWidget', 'refresh-page');
expectStateAction('MyWidget', 'refresh-page');

Implementation

void expectStateAction(String stateName, String action, {int? times}) {
  final actions = NyStateTestHelpers.getActionsFor(
    stateName,
  ).where((a) => a.action == action).toList();
  if (times != null) {
    expect(
      actions.length,
      times,
      reason:
          'Expected action "$action" on "$stateName" to fire $times '
          'time(s) but found ${actions.length}',
    );
  } else {
    expect(
      actions,
      isNotEmpty,
      reason: 'Expected action "$action" to have been fired on "$stateName"',
    );
  }
}