@@ -16,6 +16,7 @@ import {BrowserXhr} from 'angular2/src/http/backends/browser_xhr';
1616import { XHRConnection , XHRBackend } from 'angular2/src/http/backends/xhr_backend' ;
1717import { bind , Injector } from 'angular2/di' ;
1818import { Request } from 'angular2/src/http/static_request' ;
19+ import { Headers } from 'angular2/src/http/headers' ;
1920import { Map } from 'angular2/src/facade/collection' ;
2021import { RequestOptions , BaseRequestOptions } from 'angular2/src/http/base_request_options' ;
2122import { BaseResponseOptions , ResponseOptions } from 'angular2/src/http/base_response_options' ;
@@ -24,6 +25,7 @@ import {ResponseTypes} from 'angular2/src/http/enums';
2425var abortSpy ;
2526var sendSpy ;
2627var openSpy ;
28+ var setRequestHeaderSpy ;
2729var addEventListenerSpy ;
2830var existingXHRs = [ ] ;
2931
@@ -33,13 +35,15 @@ class MockBrowserXHR extends BrowserXhr {
3335 open : any ;
3436 response : any ;
3537 responseText : string ;
38+ setRequestHeader : any ;
3639 callbacks : Map < string , Function > ;
3740 constructor ( ) {
3841 super ( ) ;
3942 var spy = new SpyObject ( ) ;
4043 this . abort = abortSpy = spy . spy ( 'abort' ) ;
4144 this . send = sendSpy = spy . spy ( 'send' ) ;
4245 this . open = openSpy = spy . spy ( 'open' ) ;
46+ this . setRequestHeader = setRequestHeaderSpy = spy . spy ( 'setRequestHeader' ) ;
4347 this . callbacks = new Map ( ) ;
4448 }
4549
@@ -109,6 +113,16 @@ export function main() {
109113 new MockBrowserXHR ( ) ) ;
110114 expect ( sendSpy ) . toHaveBeenCalledWith ( body ) ;
111115 } ) ;
116+
117+ it ( 'should attach headers to the request' , ( ) => {
118+ var headers = new Headers ( { 'Content-Type' : 'text/xml' , 'Breaking-Bad' : '<3' } ) ;
119+
120+ var base = new BaseRequestOptions ( ) ;
121+ new XHRConnection ( new Request ( base . merge ( new RequestOptions ( { headers : headers } ) ) ) ,
122+ new MockBrowserXHR ( ) ) ;
123+ expect ( setRequestHeaderSpy ) . toHaveBeenCalledWith ( 'Content-Type' , [ 'text/xml' ] ) ;
124+ expect ( setRequestHeaderSpy ) . toHaveBeenCalledWith ( 'Breaking-Bad' , [ '<3' ] ) ;
125+ } ) ;
112126 } ) ;
113127 } ) ;
114128}
0 commit comments