Task<S, F>.fail constructor

Task<S, F>.fail(
  1. F value, [
  2. Object? exception,
  3. StackTrace? stack
])

Creates a task that immediately fails with the given value, exception, and stack trace.

This is used for testing.

test('Example', () {
  when(() => temperatureClient.fetch(any()))
    .thenReturn(Task.fail('Network error'));

  final result = await weatherRepository.fetch('London').run();

  expect(result.asFailure, 'Network error');
});

Implementation

Task.fail(F value, [Object? exception, StackTrace? stack])
  : this._(t.Task.fail(value, exception, stack));