当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript MockConnection.mockError方法代码示例

本文整理汇总了TypeScript中@angular/http/testing.MockConnection.mockError方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MockConnection.mockError方法的具体用法?TypeScript MockConnection.mockError怎么用?TypeScript MockConnection.mockError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@angular/http/testing.MockConnection的用法示例。


在下文中一共展示了MockConnection.mockError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: update

    public update(connection: MockConnection) {

        const requestPlayer = JSON.parse(connection.request.getBody());
        const validationResult = this.playerDb.validate(requestPlayer);

        if (validationResult === true) {

            let updatedPlayer = this.playerDb.save(requestPlayer);
            if (updatedPlayer === false) {

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

            } else {

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

            }

        } else {

            connection.mockError(new ErrorResponse(new ResponseOptions({
                body: JSON.stringify({errors: validationResult}),
                status: 422
            })));

        }
    }
开发者ID:feibeck,项目名称:fussi,代码行数:32,代码来源:player-api.ts

示例2: setTimeout

    setTimeout(() => {
      // fake authenticate api end point
      if (connection.request.url.endsWith('/api/authenticate/login') && connection.request.method === RequestMethod.Post) {
        let params = JSON.parse(connection.request.getBody());

        // check user credentials and return fake jwt token if valid
        let found: User = USERS.find((user: User) => {return (params.username === user.username);});
        if (found) {
          if(params.password === found.password) {
            connection.mockRespond(new Response(
              new ResponseOptions({status: 200, body: {token: 'fake-token-jwt', user: found}})
            ));
          }else{
            connection.mockError(new MockError(new ResponseOptions({type:ResponseType.Error, status:400, body: JSON.stringify({code: 2, message: 'The password does not match '})})));
          }
        } else {
          connection.mockError(new MockError(new ResponseOptions({type:ResponseType.Error, status:400, body: JSON.stringify({code: 1, message: 'Username does not exists'})})));
        }

      }

      if (connection.request.url.endsWith('/api/authenticate/logout') && connection.request.method === RequestMethod.Post) {
        let params = JSON.parse(connection.request.getBody());
        connection.mockRespond(new Response(
          new ResponseOptions({status: 200, body: true})
        ));
      }
    }, 100);
开发者ID:jaffbeto,项目名称:angular-login,代码行数:28,代码来源:fake-backend.ts

示例3: Error

 mockBackend.connections.subscribe((c: MockConnection) => {
     if (responseMessageSuccess) {
         c.mockRespond(userResponse);
     } else {
         c.mockError(new Error('login failed'));
     }
 });
开发者ID:iraghumitra,项目名称:incubator-metron,代码行数:7,代码来源:authentication.service.spec.ts

示例4: it

 it('GET with malformed error', (done) => {
     let connection: MockConnection;
     backend.connections.subscribe((cn: MockConnection) => connection = cn);
     client.get(someUrl).subscribe(
         next => {
             expect('Should not enter success case').toBeUndefined();
             done();
         },
         error => {
             expect(error).toBeDefined();
             expect(error.message).toBeDefined();
             expect(error.message).toBe('Internal Server Error');
             expect(error.code).toBe('500');
             const theMalFormedError: IGAEvent = window.dataLayer[0];
             expect(theMalFormedError.event).toBe('Edge_malFormedError');
             expect(theMalFormedError.target).toBe('ProductsSPA');
             expect(theMalFormedError.action).toBe(someUrl);
             expect(theMalFormedError['target-properties']).toBe('{"context":[]}');
             done();
         }
     );
     const err: any = newMalFormedError();
     err.name = 'error name';
     connection.mockError(err);
 });
开发者ID:gabyvs,项目名称:ng2-ue-utils,代码行数:25,代码来源:client.spec.ts

示例5:

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

            if(connection.request.url.endsWith("/widgets")) {
                connection.mockRespond(mockResponse);
            }

            connection.mockError(Error("request url did not match expected url"));

    });
开发者ID:training4developers,项目名称:ng2-widgets-app,代码行数:9,代码来源:widgets.service.spec.ts

示例6: it

    it('redirects to login on a 401 error', () => {
      let connection: MockConnection;
      token = null;

      spyOn(mockRouter, 'navigate');
      mockBackend.connections.subscribe(c => connection = c);
      service.get('http://test.dr.who/companions').catch(res => Observable.empty()).subscribe();
      const response = new Response(new ResponseOptions({
        status: 401
      }));
      connection.mockError(response as any as Error);
      expect(mockRouter.navigate).toHaveBeenCalledTimes(1);
      expect(mockRouter.navigate).toHaveBeenCalledWith(['authentication', 'login']);
    });
开发者ID:kensodemann,项目名称:time-trax,代码行数:14,代码来源:time-trax-http.service.spec.ts

示例7: it

    it('shouldn\'t log an user (bad cred + bad error)', fakeAsync(() => {

        var user: User;
        let error;

        twAPIService.login("m@m.com", "qwerty").then(
            response => { user = response; },
            reject => { error = reject; }
        );
        lastConnection.mockError(new Error());
        tick();
        expect(user).toBeUndefined();
        expect(error).toBeDefined();
        expect(lastConnection.request.url).toEqual(twAPIService.config.getAPIUrl() + "users", "should be consumed");
    }));
开发者ID:Toolwatchapp,项目名称:tw-common,代码行数:15,代码来源:twapi.service.spec.ts

示例8: it

  it('Logs error on failed model retrieval', async(inject([TestHttpStore, MockBackend], (s: TestHttpStore, b: MockBackend) => {

    let logSpy = spyOn((s as any).logger, 'error');

    let connection: MockConnection;
    b.connections.subscribe((c: MockConnection) => connection = c);

    const testPromise = s.findOne(null)
      .catch((res) => {
        expect(logSpy)
          .toHaveBeenCalledWith('Internal Error');
      });
    connection.mockError(new Error('Internal Error'));

    return testPromise;

  })));
开发者ID:ubiquits,项目名称:ubiquits,代码行数:17,代码来源:http.store.spec.ts


注:本文中的@angular/http/testing.MockConnection.mockError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。