当前位置: 首页>>代码示例>>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;未经允许,请勿转载。