Skip to content

Commit

Permalink
✅ Added test to see if exception are passed up
Browse files Browse the repository at this point in the history
  • Loading branch information
Guldem committed Apr 6, 2024
1 parent d5a8d4a commit 2c6bf7a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions chopper/test/chain/interceptor_chain_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:chopper/src/chain/chain.dart';
import 'package:chopper/src/chain/interceptor_chain.dart';
import 'package:chopper/src/interceptors/interceptor.dart';
import 'package:chopper/src/interceptors/internal_interceptor.dart';
import 'package:chopper/src/interceptors/request_converter_interceptor.dart';
import 'package:chopper/src/interceptors/response_converter_interceptor.dart';
import 'package:chopper/src/request.dart';
import 'package:chopper/src/response.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -153,6 +155,50 @@ void main() {
);
});
});

group('Chain exception tests', () {
late Request mockRequest;
late InterceptorChain interceptorChain;
setUp(() {
mockRequest = Request(
'GET',
Uri.parse('bar'),
Uri.parse('http://localhost'),
body: 'Test',
);
});

test('Exception thrown inside the interceptor chain will be passed up',
() async {
interceptorChain = InterceptorChain(
interceptors: [
RequestConverterInterceptor(null, null),
PassthroughInterceptor(),
PassthroughInterceptor(),
ResponseConverterInterceptor(
converter: null,
errorConverter: null,
responseConverter: null,
),
ExceptionThrowingInterceptor(),
],
request: mockRequest,
);

expect(
() => interceptorChain.proceed(mockRequest),
throwsA(isA<Exception>().having(
(e) => e.toString(), 'message', 'Exception: Test exception')),
);
});
});
}

class ExceptionThrowingInterceptor implements Interceptor {
@override
FutureOr<Response<BodyType>> intercept<BodyType>(Chain<BodyType> chain) {
throw Exception('Test exception');
}
}

class RequestModifierInterceptor implements Interceptor {
Expand Down

0 comments on commit 2c6bf7a

Please sign in to comment.