@@ -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.
@@ -952,6 +951,60 @@ void main() {
952
951
flush ();
953
952
}));
954
953
});
954
+
955
+ describe ('request interceptors' , () {
956
+ bool interceptorCalled;
957
+
958
+ beforeEach (() {
959
+ interceptorCalled = false ;
960
+ });
961
+
962
+ describe ('synchronous' , () {
963
+ beforeEachModule ((Module module) {
964
+ module.bind (HttpInterceptors , toValue: new HttpInterceptors ()
965
+ // The first interceptor is sync, causing the second interceptor to be called synchronously
966
+ ..add (new HttpInterceptor (request: (cfg) => cfg))
967
+ ..add (new HttpInterceptor (request: (cfg) {
968
+ interceptorCalled = true ;
969
+ return cfg;
970
+ })));
971
+ });
972
+
973
+ it ('should call backend synchronously if request interceptor chain is '
974
+ 'synchronous' , async (() {
975
+ backend.expect ('POST' , '/url' , '' ).respond ('' );
976
+ http (url: '/url' , method: 'POST' , data: '' );
977
+ expect (interceptorCalled).toBe (true );
978
+ expect (backend.responses.isEmpty).toBe (false ); // request made immediately
979
+ flush ();
980
+ }));
981
+ });
982
+
983
+ describe ('asynchronous' , () {
984
+ beforeEachModule ((Module module) {
985
+ module.bind (HttpInterceptors , toValue: new HttpInterceptors ()
986
+ // The first interceptor is async, causing the second interceptor to be
987
+ // called in a microtask
988
+ ..add (new HttpInterceptor (request: (cfg) => new Future .value (cfg)))
989
+ ..add (new HttpInterceptor (request: (cfg) {
990
+ interceptorCalled = true ;
991
+ return cfg;
992
+ })));
993
+ });
994
+
995
+ it ('should call backend asynchronously if request interceptor chain is '
996
+ 'asynchronous' , async (() {
997
+ backend.expect ('POST' , '/url' , '' ).respond ('' );
998
+ http (url: '/url' , method: 'POST' , data: '' );
999
+ expect (interceptorCalled).toBe (false );
1000
+ expect (backend.expectations.isEmpty).toBe (false );
1001
+ backend.verifyNoOutstandingRequest ();
1002
+
1003
+ flush ();
1004
+ expect (interceptorCalled).toBe (true );
1005
+ }));
1006
+ });
1007
+ });
955
1008
});
956
1009
957
1010
describe ('url rewriting' , () {
0 commit comments