Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
En el caso de prueba angular, realice una llamada de método estático desde un servicio donde HTTP get cargará json que está almacenado. Y devuelve el json al servicio.

Soy un nuevo caso de prueba angular. Y golpeó con la carga de JSON a través de una llamada HTTP.

  • Básicamente, desde un archivo de especificaciones de servicio: "url-service.spec" llama a un método estático que se encuentra en otro servicio: "load-json.service.spec".
  • Aquí, en "load-json.pservice.spec", hace que HTTP reciba una llamada para cargar json y también se suscribe allí y luego devuelve solo JSON. [NOTA: no devuelve observable al servicio de URL].

Podemos llamar al método estático usando spyOn pero no pude averiguar cómo inyectar HTTP y cargar json y suscribirme allí

¡¡Realmente necesito ayuda!! y muchas gracias de antemano

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Parece que estás abordando el problema de manera incorrecta. Debe simular el método en "load-json.service.ts", el método simulado debe devolver el JSON exacto

Si está probando algunos componentes, lo siguiente es lo que sugiero.

Aviso en los proveedores, estamos obligando al componente a usar nuestro LoadJsonService simulado.

 ... const jsonDataObj = {foo: 'bar'}; const mockedLoadJsonService = { getJson:()=> JSON.stringify(jsonDataObj) } beforeEach(async () => { await TestBed.configureTestingModule({ imports: [ ... ], declarations: [...], providers: [ { provide: LoadJsonService, useValue: mockedLoadJsonService }, ], }).compileComponents(); }); ...
about 4 years ago · Juan Pablo Isaza Report

0

Te puedo dar un ejemplo de mi proyecto. Tal vez te ayude a hacerte una idea.

 describe("Interviews service", () => { let httpClientSpy: jasmine.SpyObj<HttpClient>; let interviewsService: InterviewsService; beforeEach(() => { const apiUrlsServiceFake = jasmine.createSpyObj('ApiUrlsBuilderService', ['getApiUrl']); httpClientSpy = jasmine.createSpyObj('HttpClient', ['post']); interviewsService = new InterviewsService(httpClientSpy, apiUrlsServiceFake); }); it('should create new interview and return new interview data', (done: DoneFn) => { const expectedNewInterviewData: NewInterviewData = { id: 1234, encodedId: "qweasd" }; httpClientSpy.post.and.returnValue(asyncData(expectedNewInterviewData)); interviewsService.createNewInterview(1111, "New interview").subscribe({ next: newIwData => { expect(newIwData).withContext("Expect new interview data").toEqual(expectedNewInterviewData); done(); }, error: done.fail }); expect(httpClientSpy.post.calls.count()).withContext('one call').toBe(1); }); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!