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

371
Views
Error de caso de prueba de Jasmine: se ha llamado al error de espía

Tengo el siguiente código que necesita ser probado en Jasmine

 sampleMethod() { if (this.sampleObject) { // business logic } else { console.error('sampleObject not initialized'); } }

Me había referido a Spying on console.error() con Jasmine para agregar la prueba jasmine para monitorear console.error.

 it('should check for console.error', () => { spyOn(console, 'error'); component.sampleMethod(); expect(console.error).toHaveBeenCalled(); });

Sin embargo, recibo el siguiente error:

 Error: Expected spy error to have been called.

SampleObject no está definido. También intenté agregar spyOn a beforeEach . Aún así, estoy recibiendo el error.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

¿Puede probar esto para asegurarse de que sampleObject no esté definido e intentar asignar el espía a una variable?

 it('should check for console.error', () => { const errorSpy = spyOn(console, 'error'); component.sampleObject = undefined; component.sampleMethod(); expect(errorSpy).toHaveBeenCalled(); });
about 4 years ago · Santiago Gelvez 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!