expectErrorCount static method

void expectErrorCount(
  1. int expectedCount,
  2. void test()
)

Verify that a specific number of errors were logged

Implementation

static void expectErrorCount(
  int expectedCount,
  void Function() test,
) {
  int errorCount = 0;

  withErrorLogger(
    (error) => errorCount++,
    test,
  );

  if (errorCount != expectedCount) {
    throw Exception('Expected $expectedCount errors but got $errorCount');
  }
}