expectListCountFinder method

void expectListCountFinder(
  1. Finder listFinder, {
  2. required int expected,
  3. Finder? itemFinder,
  4. bool atLeast = false,
  5. String description = 'target list',
})

Implementation

void expectListCountFinder(
  Finder listFinder, {
  required int expected,
  Finder? itemFinder,
  bool atLeast = false,
  String description = 'target list',
}) {
  return RunnerBenchmark.sync('assertion', 'expectListCountFinder', () {
    if (listFinder.evaluate().isEmpty) {
      throw EnsembleTestFailure('expectListCount: $description not found.');
    }
    final count = itemFinder != null
        ? find
            .descendant(of: listFinder, matching: itemFinder)
            .evaluate()
            .length
        : find
            .descendant(
                of: listFinder, matching: find.byWidgetPredicate((_) => true))
            .evaluate()
            .length;
    if (atLeast) {
      if (count < expected) {
        throw EnsembleTestFailure(
          'Expected at least $expected items in $description, found $count.',
        );
      }
      return;
    }
    if (count != expected) {
      throw EnsembleTestFailure(
        'Expected $expected items in $description, found $count.',
      );
    }
  });
}