parent
256bc8acdd
commit
5c62e300e1
|
@ -12,7 +12,7 @@ import 'rxjs/add/operator/toPromise';
|
||||||
import {ddescribe, describe, iit, it} from '@angular/core/testing/src/testing_internal';
|
import {ddescribe, describe, iit, it} from '@angular/core/testing/src/testing_internal';
|
||||||
|
|
||||||
import {HttpClient} from '../src/client';
|
import {HttpClient} from '../src/client';
|
||||||
import {HttpEventType, HttpResponse} from '../src/response';
|
import {HttpErrorResponse, HttpEventType, HttpResponse} from '../src/response';
|
||||||
import {HttpClientTestingBackend} from '../testing/src/backend';
|
import {HttpClientTestingBackend} from '../testing/src/backend';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
|
@ -123,5 +123,15 @@ export function main() {
|
||||||
.flush('hello world');
|
.flush('hello world');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('makes a request for an error response', () => {
|
||||||
|
it('with a JSON body', (done: DoneFn) => {
|
||||||
|
client.get('/test').subscribe(() => {}, (res: HttpErrorResponse) => {
|
||||||
|
expect(res.error.data).toEqual('hello world');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
backend.expectOne('/test').flush(
|
||||||
|
{'data': 'hello world'}, {status: 500, statusText: 'Server error'});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -61,12 +61,11 @@ export class TestRequest {
|
||||||
if (statusText === undefined) {
|
if (statusText === undefined) {
|
||||||
throw new Error('statusText is required when setting a custom status.');
|
throw new Error('statusText is required when setting a custom status.');
|
||||||
}
|
}
|
||||||
const res = {body, headers, status, statusText, url};
|
|
||||||
if (status >= 200 && status < 300) {
|
if (status >= 200 && status < 300) {
|
||||||
this.observer.next(new HttpResponse<any>(res));
|
this.observer.next(new HttpResponse<any>({body, headers, status, statusText, url}));
|
||||||
this.observer.complete();
|
this.observer.complete();
|
||||||
} else {
|
} else {
|
||||||
this.observer.error(new HttpErrorResponse(res));
|
this.observer.error(new HttpErrorResponse({error: body, headers, status, statusText, url}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue