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


TypeScript mock_backend.MockBackend類代碼示例

本文整理匯總了TypeScript中http/src/backends/mock_backend.MockBackend的典型用法代碼示例。如果您正苦於以下問題:TypeScript MockBackend類的具體用法?TypeScript MockBackend怎麽用?TypeScript MockBackend使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MockBackend類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

  describe('http', () => {
    var url = 'http://foo.bar';
    var http: Http;
    var injector: Injector;
    var backend: MockBackend;
    var baseResponse;
    beforeEach(() => {
      injector = Injector.resolveAndCreate([
        BaseRequestOptions,
        MockBackend,
        bind(Http).toFactory(
            function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
              return new Http(backend, defaultOptions);
            },
            [MockBackend, BaseRequestOptions])
      ]);
      http = injector.get(Http);
      backend = injector.get(MockBackend);
      baseResponse = new Response(new ResponseOptions({body: 'base response'}));
    });

    afterEach(() => backend.verifyNoPendingRequests());

    describe('Http', () => {
      describe('.request()', () => {
        it('should return an Observable',
           () => { expect(ObservableWrapper.isObservable(http.request(url))).toBe(true); });


        it('should accept a fully-qualified request as its only parameter',
           inject([AsyncTestCompleter], (async) => {
             ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
               expect(c.request.url).toBe('https://google.com');
               c.mockRespond(new Response(new ResponseOptions({body: 'Thank you'})));
               async.done();
             });
             ObservableWrapper.subscribe(
                 http.request(new Request(new RequestOptions({url: 'https://google.com'}))),
                 (res) => {});
           }));


        it('should perform a get request for given url if only passed a string',
           inject([AsyncTestCompleter], (async) => {
             ObservableWrapper.subscribe<MockConnection>(backend.connections,
                                                         c => c.mockRespond(baseResponse));
             ObservableWrapper.subscribe<Response>(http.request('http://basic.connection'), res => {
               expect(res.text()).toBe('base response');
               async.done();
             });
           }));

        // TODO: make dart not complain about "argument type 'Map' cannot be assigned to the
        // parameter type 'IRequestOptions'"
        // xit('should perform a get request for given url if passed a dictionary',
        //     inject([AsyncTestCompleter], async => {
        //       ObservableWrapper.subscribe(backend.connections, c => c.mockRespond(baseResponse));
        //       ObservableWrapper.subscribe(http.request(url, {method: RequestMethods.GET}), res =>
        //       {
        //         expect(res.text()).toBe('base response');
        //         async.done();
        //       });
        //     }));
      });


      describe('.get()', () => {
        it('should perform a get request for given url', inject([AsyncTestCompleter], async => {
             ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
               expect(c.request.method).toBe(RequestMethods.GET);
               backend.resolveAllConnections();
               async.done();
             });
             ObservableWrapper.subscribe(http.get(url), res => {});
           }));
      });


      describe('.post()', () => {
        it('should perform a post request for given url', inject([AsyncTestCompleter], async => {
             ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
               expect(c.request.method).toBe(RequestMethods.POST);
               backend.resolveAllConnections();
               async.done();
             });
             ObservableWrapper.subscribe(http.post(url, 'post me'), res => {});
           }));


        it('should attach the provided body to the request', inject([AsyncTestCompleter], async => {
             var body = 'this is my post body';
             ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
               expect(c.request.text()).toBe(body);
               backend.resolveAllConnections();
               async.done();
             });
             ObservableWrapper.subscribe(http.post(url, body), res => {});
           }));
      });

//.........這裏部分代碼省略.........
開發者ID:goderbauer,項目名稱:angular,代碼行數:101,代碼來源:http_spec.ts

示例2: afterEach

 afterEach(() => backend.verifyNoPendingRequests());
開發者ID:goderbauer,項目名稱:angular,代碼行數:1,代碼來源:http_spec.ts

示例3: expect

 ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
   expect(c.request.method).toBe(RequestMethods.HEAD);
   backend.resolveAllConnections();
   async.done();
 });
開發者ID:goderbauer,項目名稱:angular,代碼行數:5,代碼來源:http_spec.ts


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