當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jsonp.JsonpClientBackend類代碼示例

本文整理匯總了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();
     });
   });
 });
開發者ID:BobChao87,項目名稱:angular,代碼行數:47,代碼來源:jsonp_spec.ts

示例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();
 });
開發者ID:BobChao87,項目名稱:angular,代碼行數:9,代碼來源:jsonp_spec.ts

示例3: expect

 () => expect(() => backend.handle(SAMPLE_REQ.clone<never>({responseType: 'text'})))
開發者ID:BobChao87,項目名稱:angular,代碼行數:1,代碼來源:jsonp_spec.ts


注:本文中的@angular/common/http/src/jsonp.JsonpClientBackend類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。