• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript testing.MockConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mock_backend.MockConnection类代码示例发布时间:2022-05-28
下一篇:
TypeScript testing.MockBackend类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap