How to use the @angular/http.Response function in @angular/http

To help you get started, we’ve selected a few @angular/http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dotCMS / core-web / src / app / portlets / shared / dot-content-types-edit / components / fields / dot-content-type-fields-variables / services / dot-field-variables.service.spec.ts View on Github external
const field: DotCMSContentTypeField = {
            ...dotcmsContentTypeFieldBasicMock,
            contentTypeId: '1b',
            id: '1'
        };

        this.fieldVariableService.load(field).subscribe((variables: DotFieldVariable[]) => {
            expect(variables).toEqual(mockResponse.entity);
            expect(0).toBe(this.lastConnection.request.method); // 2 is GET method
            expect(this.lastConnection.request.url)
                .toContain(`v1/contenttype/${field.contentTypeId}/fields/id/${field.id}/variables`);
        });

        this.lastConnection.mockRespond(
            new Response(
                new ResponseOptions({
                    body: JSON.stringify(mockResponse)
                })
            )
        );
    });
github angular / angular / aio / content / examples / testing / src / app / model / http-hero.service.spec.ts View on Github external
beforeEach(() => {

      backend = TestBed.get(XHRBackend);
      http = TestBed.get(Http);

      service = new HttpHeroService(http);
      fakeHeroes = makeHeroData();
      let options = new ResponseOptions({status: 200, body: {data: fakeHeroes}});
      response = new Response(options);
    });
github dotCMS / core-web / src / app / api / services / dot-personalize / dot-personalize.service.spec.ts View on Github external
it('should despersonalized', () => {
        const pageId = 'a';
        const personaTag = 'b';
        this.dotPersonalizeService.despersonalized(pageId, personaTag).subscribe();

        this.lastConnection.mockRespond(
            new Response(
                new ResponseOptions({
                    body: []
                })
            )
        );
        expect(this.lastConnection.request.method).toBe(RequestMethod.Delete);
        expect(this.lastConnection.request.url).toContain(
            `/api/v1/personalization/pagepersonas/page/${pageId}/personalization/${personaTag}`
        );
    });
});
github microsoft / IIS.WebManager / src / app / runtime / wac / services / powershell-service.ts View on Github external
}).map(res => {
        let response = new Response(res)
        if (res.status < 200 || res.status >= 400) {
          throw response
        }
        return response
    })
  }
github reflectoring / infiniboard / dashy / src / app / dashboard / shared / widget.service.spec.ts View on Github external
private createFakeResponse(url: string, body: any, status = 200): Observable {
    const responseOptionsArgs = {
      body: body,
      status: status,
      statusText: 'OK',
      url: url,
      type: ResponseType.Basic
    };

    return Observable.of(new Response(new ResponseOptions(responseOptionsArgs)));
  }
github apache / ambari-logsearch / ambari-logsearch-web / src / app / services / mock-api-data.service.ts View on Github external
return new Observable((subscriber: Subscriber) => subscriber.error(
        new Response(createErrorResponse(
          interceptorArgs.requestInfo.req, 404, 'Not found'
        )))
      );
github bulktrade / SMSC / modules / admin / src / app / shared / crud-repository.spec.ts View on Github external
mockBackend.connections.subscribe(connection => {
            let response = new ResponseOptions({status: 204, statusText: 'NO CONTENT'});
            connection.mockRespond(new Response(response));
        });
        service.deleteResourceById(1)
github bleenco / abstruse / src / app / components / app-builds / app-builds.component.spec.ts View on Github external
beforeEach(async(inject([Http, Router, XHRBackend], (http: Http, router: Router, be: MockBackend) => {
      backend = be;
      apiService = new ApiService(http, router);
      socketService = new SocketService();
      authService = new AuthService(apiService, socketService, router);
      fakeBuilds = buildsData.data;
      let optionsBuild = new ResponseOptions({ status: 200, body: { data: fakeBuilds } });
      responseBuilds = new Response(optionsBuild);
      backend.connections.subscribe((c: MockConnection) => c.mockRespond(responseBuilds));
    })));
github ecsnavarretemit / sarai-interactive-maps / src / app / map / shared / services / tile-layer.service.spec.ts View on Github external
backend.connections.subscribe((connection: MockConnection) => {
      const options = new ResponseOptions({
        body: JSON.stringify(dataToSend)
      });

      connection.mockRespond(new Response(options));

      expect(connection.request.method).toEqual(RequestMethod.Get);
    });
github dotCMS / core-web / src / app / api / services / site-service.spec.ts View on Github external
let currentCounter = 5;
        let newCurrentSite: Site;
        let loginService: LoginServiceMock = this.injector.get(LoginService);

        this.siteService.switchSite$.subscribe(site => newCurrentSite = site);

        let mockResponse = {
                entity: {
                    currentSite: currentSite,
                    totalRecords: currentCounter,
                }
            };

        loginService.tiggerWatchUser();

        this.lastCurrentSiteConnection.mockRespond(new Response(new ResponseOptions({
            body: JSON.stringify(mockResponse)
        })));

        tick();
        expect(this.lastCurrentSiteConnection.request.url).toContain('v1/site/currentSite');
        expect(currentSite).toEqual(mockResponse.entity.currentSite);
        expect(currentCounter).toEqual(mockResponse.entity.totalRecords);
    }));