expectErr<T> function

Problem expectErr<T>(
  1. Result<T> result, {
  2. String? because,
})

Assert result is Err and return its problem; throws otherwise.

Implementation

Problem expectErr<T>(Result<T> result, {String? because}) => switch (result) {
  Ok<T>(:final value) => throw AssertionError(
    'expected Err but got Ok($value)${because == null ? '' : ' — $because'}',
  ),
  Err<T>(:final problem) => problem,
};