@@ -88,9 +88,8 @@ void main() {
88
88
// we don't care about the data field.
89
89
backend.expect ('POST' , '/url' , 'null' ).respond ('' );
90
90
91
- http (url: '/url' , method: 'POST' );
92
91
expect (() {
93
- flush ( );
92
+ http (url : '/url' , method : 'POST' );
94
93
}).toThrow ('with different data' );
95
94
96
95
// satisfy the expectation for our afterEach's assert.
@@ -936,6 +935,60 @@ void main() {
936
935
flush ();
937
936
}));
938
937
});
938
+
939
+ describe ('request interceptors' , () {
940
+ bool interceptorCalled;
941
+
942
+ beforeEach (() {
943
+ interceptorCalled = false ;
944
+ });
945
+
946
+ describe ('synchronous' , () {
947
+ beforeEachModule ((Module module) {
948
+ module.bind (HttpInterceptors , toValue: new HttpInterceptors ()
949
+ // The first interceptor is sync, causing the second interceptor to be called synchronously
950
+ ..add (new HttpInterceptor (request: (cfg) => cfg))
951
+ ..add (new HttpInterceptor (request: (cfg) {
952
+ interceptorCalled = true ;
953
+ return cfg;
954
+ })));
955
+ });
956
+
957
+ it ('should call backend synchronously if request interceptor chain is '
958
+ 'synchronous' , async (() {
959
+ backend.expect ('POST' , '/url' , '' ).respond ('' );
960
+ http (url: '/url' , method: 'POST' , data: '' );
961
+ expect (interceptorCalled).toBe (true );
962
+ expect (backend.responses.isEmpty).toBe (false ); // request made immediately
963
+ flush ();
964
+ }));
965
+ });
966
+
967
+ describe ('asynchronous' , () {
968
+ beforeEachModule ((Module module) {
969
+ module.bind (HttpInterceptors , toValue: new HttpInterceptors ()
970
+ // The first interceptor is async, causing the second interceptor to be
971
+ // called in a microtask
972
+ ..add (new HttpInterceptor (request: (cfg) => new Future .value (cfg)))
973
+ ..add (new HttpInterceptor (request: (cfg) {
974
+ interceptorCalled = true ;
975
+ return cfg;
976
+ })));
977
+ });
978
+
979
+ it ('should call backend asynchronously if request interceptor chain is '
980
+ 'asynchronous' , async (() {
981
+ backend.expect ('POST' , '/url' , '' ).respond ('' );
982
+ http (url: '/url' , method: 'POST' , data: '' );
983
+ expect (interceptorCalled).toBe (false );
984
+ expect (backend.expectations.isEmpty).toBe (false );
985
+ backend.verifyNoOutstandingRequest ();
986
+
987
+ flush ();
988
+ expect (interceptorCalled).toBe (true );
989
+ }));
990
+ });
991
+ });
939
992
});
940
993
941
994
describe ('url rewriting' , () {
0 commit comments