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


TypeScript testing.MockConnection類代碼示例

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


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

示例1: it

    it('returns the data from the response', () => {
      let connection: MockConnection;
      mockBackend.connections.subscribe(c => connection = c);

      let result;
      service.get('42').subscribe((res) => { result = res; });
      connection.mockRespond(new Response(new ResponseOptions({
        status: 200,
        body: {
          _id: '42',
          endDate: '2016-11-30',
          userRid: 'me'
        }
      })));
      expect(result).toEqual(new Timesheet({
        _id: '42',
        endDate: '2016-11-30',
        userRid: 'me'
      }));
    });
開發者ID:kensodemann,項目名稱:time-trax,代碼行數:20,代碼來源:timesheet.service.spec.ts

示例2: it

    it('add a client release date', () => {
      let connection: MockConnection;
      mockBackend.connections.subscribe(c => connection = c);

      let result: Version;
      service.get().subscribe((res) => { result = res; });
      connection.mockRespond(new Response(new ResponseOptions({
        status: 200,
        body: [{ id: '2.0.4', name: 'Misty (2.0.4)', releaseDate: '2016-07-15' }]
      })));
      connection.mockRespond(new Response(new ResponseOptions({
        status: 200,
        body: {
          id: '1.2.0',
          name: 'rusty nail',
          date: '2017-05-10'
        }
      })));
      expect(result.releaseDate).toEqual(moment('2017-05-10'));
    });
開發者ID:kensodemann,項目名稱:time-trax,代碼行數:20,代碼來源:version.service.spec.ts

示例3: expect

        mockBackend.connections.subscribe((mockConnection:MockConnection)=>{

            if(mockConnection.request.url == '/token'){
                expect(mockConnection.request.method).toBe(RequestMethod.Post);
            console.info(mockConnection.request.getBody());
            expect(mockConnection.request.headers.get('Content-Type')).toEqual('x-www-form-urlencoded');
            mockConnection.mockRespond( new Response(new ResponseOptions({body: login_response})));
            }

            
        });
開發者ID:shafihuzaib,項目名稱:cdp-ng-boilerplate,代碼行數:11,代碼來源:auth-api-service.spec.ts

示例4: it

    it('gets the specified project', () => {
      let connection: MockConnection;
      mockBackend.connections.subscribe(c => connection = c);

      let result;
      service.get('42731138').subscribe((res) => { result = res; });
      expect(connection.request.url).toEqual(`${environment.dataService}/projects/42731138`);
      expect(connection.request.method).toEqual(RequestMethod.Get);
      connection.mockRespond(new Response(new ResponseOptions({
        status: 200,
        body: {
          _id: '42731138',
          name: 'Deep Geeky Thoughts About Total Control'
        }
      })));
      expect(result).toEqual(new Project({
        _id: '42731138',
        name: 'Deep Geeky Thoughts About Total Control'
      }));
    });
開發者ID:kensodemann,項目名稱:time-trax,代碼行數:20,代碼來源:project.service.spec.ts

示例5: ResponseOptions

 (connection: MockConnection) => {
   connection.mockRespond(new Response(
     new ResponseOptions({
         body: [
           {
             id: 2,
             username: "username"
           }]
       }
     )));
 });
開發者ID:aswinrbt,項目名稱:gadget_board,代碼行數:11,代碼來源:account.service.spec.ts

示例6: it

 it('saves the token if the login is successful', () => {
   let connection: MockConnection;
   mockBackend.connections.subscribe(c => connection = c);
   spyOn(authenticationTokenService, 'set');
   service.login('user', 'password').subscribe((res) => {
     expect(authenticationTokenService.set).toHaveBeenCalledTimes(1);
     expect(authenticationTokenService.set).toHaveBeenCalledWith('IAmToken');
   });
   connection.mockRespond(new Response(new ResponseOptions({
     status: 200,
     body: {
       success: true,
       user: {
         firstName: 'James',
         lastName: 'Jones'
       },
       token: 'IAmToken'
     }
   })));
 });
開發者ID:kensodemann,項目名稱:time-trax,代碼行數:20,代碼來源:authentication.service.spec.ts

示例7: Response

                backend.connections.subscribe((connection:MockConnection) => {
                    let mockResponseBody, response;
                    if (connection.request.url === `/${PATHS.authenticate}`) {
                        mockResponseBody = {
                            status: "success",
                            username: username,
                            sessionId: sessionId
                        };
                        response = new Response(new ResponseOptions({body: JSON.stringify(mockResponseBody)}));

                        connection.mockRespond(response);
                    } else {
                        mockResponseBody = {
                            status: "success"
                        };
                        response = new Response(new ResponseOptions({body: JSON.stringify(mockResponseBody)}));

                        connection.mockRespond(response);
                    }
                });
開發者ID:kuiqiang,項目名稱:cvp,代碼行數:20,代碼來源:auth.service.spec.ts

示例8: getPointLog

    public getPointLog(connection: MockConnection) {

        const id = parseInt(connection.request.url.match(/\/api\/player\/([0-9]+)\/pointlog/i)[1], 10);

        let response = new Response(new ResponseOptions({
            body: JSON.stringify(this.pointLogDb.get(id))
        }));

        connection.mockRespond(response);

    }
開發者ID:feibeck,項目名稱:fussi,代碼行數:11,代碼來源:player-api.ts

示例9: ResponseOptions

    backend.connections.subscribe((connection: MockConnection) => {
      const options = new ResponseOptions({
        body: JSON.stringify(MockKnowledgeApi)
      });

      connection.mockRespond(new Response(options));
      expect(connection.request.method).toEqual(RequestMethod.Get);
      expect(connection.request.url).toBe(
        `http://lookup.dbpedia.org/api/search/KeywordSearch` +
                    `?&QueryString=${searchquery}`
      );
    });
開發者ID:collinx,項目名稱:susper.com,代碼行數:12,代碼來源:knowledgeapi.service.spec.ts

示例10: get

    public get(connection: MockConnection) {

        const id = parseInt(connection.request.url.match(/\/([0-9]+)/i)[1], 10);
        const foundTournament = this.tournamentDb.get(id);

        if (foundTournament) {

            connection.mockRespond(new Response(new ResponseOptions({
                body: JSON.stringify(foundTournament)
            })));

        } else {

            connection.mockError(new ErrorResponse(new ResponseOptions({
                body: 'Tournament not found',
                status: 404
            })));

        }

    }
開發者ID:feibeck,項目名稱:fussi,代碼行數:21,代碼來源:tournament-api.ts


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