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

157
Views
Espere que se elimine el error del siguiente controlador de observable, probando Angular con Jasmine

En la aplicación Angular, tenga un controlador con el siguiente método

 onClick(): void { this.http .get('some/endpoint') .subscribe( (response) => { const editUrl = this.service.composeUrl(response); if (!editUrl) { // want to test this error is thrown, when editUrl is null throw Error('Cannot construct valid URL'); } // do something else }, () => { // request clean up } ); }

Me gustaría escribir la prueba de Jasmine para verificar que si editUrl no se puede componer a partir de la respuesta, se generará un error.

 it('when call is successful but editUrl cannot be constructed, then error is thrown', () => { mockHttp.get = jasmine .createSpy() .and.returnValue(of({})); mockService.composeUrl= jasmine .createSpy() .and.returnValue(null); expect(() => { component.onClick() }).toThrowError(); });

Mi prueba falla con:

Error: función esperada para arrojar un error.

Pero también veo en la consola del navegador que se arrojó el error Uncaught Error: Cannot construct valid URL

Creo que el problema está en que se arroja un error en el siguiente controlador de http observable, y de alguna manera se está quedando sin contexto de jazmín.

Podría solucionarlo extrayendo el siguiente controlador anónimo en la función con nombre y probar directamente esa función, pero prefiero suscribirme con funciones de flecha anónimas.

about 4 years ago · Juan Pablo Isaza
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!