MockBackend를 사용하여 단위 테스트 내부에서 내 코드에서 보낸 헤더를 확인하는 데 문제가 있습니다.
테스트 내에서 다음을 실행하고 있습니다.
injectAsync([Http, XHRBackend], (http: Http, backend: MockBackend) => {
return new Promise((pass, fail) => {
var request: Request;
backend.connections.subscribe((c: MockConnection) => {
request = c.request;
c.mockRespond(new Response(new ResponseOptions()));
})
let req_headers = new Headers({'Authorization': 'Bearer foo'});
http.get('/', new ResponseOptions({headers: req_headers})).subscribe(
() => {
// I try to get the request headers here
console.log(request.headers);
pass();
},
fail
)
})
})
그러나 헤더를 다시 읽으려고 할 때 빈 헤더 세트가 표시됩니다. 로그 문의 결과는 나에게 제공 Headers{_headersMap: Map{}}
됩니다.
내가 무엇을 놓치고 있습니까?
사실, 그것들이 있지만 headers 속성은 a Map
이므로 다음과 같이 가져와야합니다.
// All headers
for (var key of connection.request.headers.keys()) {
console.log('- key = ' + key);
}
// Authorization header
var auth = connection.request.headers.get('Authorization');
console.log('auth = '+auth);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다