Task<S, F>.fail constructor
Task<S, F>.fail (
- F value, [
- Object? exception,
- 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));