本文整理匯總了TypeScript中@angular/common/http/src/jsonp.JsonpClientBackend類的典型用法代碼示例。如果您正苦於以下問題:TypeScript JsonpClientBackend類的具體用法?TypeScript JsonpClientBackend怎麽用?TypeScript JsonpClientBackend使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了JsonpClientBackend類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('JsonpClientBackend', () => {
let home = {};
let document: MockDocument;
let backend: JsonpClientBackend;
beforeEach(() => {
home = {};
document = new MockDocument();
backend = new JsonpClientBackend(home, document);
});
it('handles a basic request', done => {
backend.handle(SAMPLE_REQ).pipe(toArray()).subscribe(events => {
expect(events.map(event => event.type)).toEqual([
HttpEventType.Sent,
HttpEventType.Response,
]);
done();
});
runOnlyCallback(home, {data: 'This is a test'});
document.mockLoad();
});
it('handles an error response properly', done => {
const error = new Error('This is a test error');
backend.handle(SAMPLE_REQ).pipe(toArray()).subscribe(undefined, (err: HttpErrorResponse) => {
expect(err.status).toBe(0);
expect(err.error).toBe(error);
done();
});
document.mockError(error);
});
describe('throws an error', () => {
it('when request method is not JSONP',
() => expect(() => backend.handle(SAMPLE_REQ.clone<never>({method: 'GET'})))
.toThrowError(JSONP_ERR_WRONG_METHOD));
it('when response type is not json',
() => expect(() => backend.handle(SAMPLE_REQ.clone<never>({responseType: 'text'})))
.toThrowError(JSONP_ERR_WRONG_RESPONSE_TYPE));
it('when callback is never called', done => {
backend.handle(SAMPLE_REQ).subscribe(undefined, (err: HttpErrorResponse) => {
expect(err.status).toBe(0);
expect(err.error instanceof Error).toEqual(true);
expect(err.error.message).toEqual(JSONP_ERR_NO_CALLBACK);
done();
});
document.mockLoad();
});
});
});
示例2: it
it('when callback is never called', done => {
backend.handle(SAMPLE_REQ).subscribe(undefined, (err: HttpErrorResponse) => {
expect(err.status).toBe(0);
expect(err.error instanceof Error).toEqual(true);
expect(err.error.message).toEqual(JSONP_ERR_NO_CALLBACK);
done();
});
document.mockLoad();
});
示例3: expect
() => expect(() => backend.handle(SAMPLE_REQ.clone<never>({responseType: 'text'})))