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

393
Views
Prueba unitaria para una declaración de cambio en Angular

Soy nuevo en las pruebas de unidades angulares y no sé cómo probar este interruptor:

 displayBadge(text: any) { switch (text) { case 'blabla': return 'badge badge-pill badge-success'; case 'lalala': return 'badge badge-pill badge-secondary'; case 'uuuu': return 'badge badge-pill badge-warning'; case 'ooooo': return 'badge badge-pill badge-warning'; case 'eeee': return 'badge badge-pill badge-warning'; case 'zzzzz': return 'badge badge-pill badge-dark'; case 'aaaaa': return 'badge badge-pill badge-dark'; case 'qqqqq': return 'badge badge-pill badge-success'; case 'ccccc': return 'badge badge-pill badge-warning'; case 'rrrrr': return 'badge badge-pill badge-success'; case 'ttttt': return 'badge badge-pill badge-warning'; case 'fffff': return 'badge badge-pill badge-success'; default: return '';

Estoy usando el complemento Simontest en VSCODE y la cobertura del código siempre me dice que me falta como el 80 % de la cobertura, que es este interruptor.

He intentado de esta manera en mi archivo spec.ts:

 it('text aaaaa', () => { component.text ='aaaaa' component.displayBadge(component.text); expect('badge badge-pill badge-secondary'); });

pero no funciona

el texto se define así en mi ts:

 @Input() text!: any;

He visto que hay otras publicaciones sobre probar un interruptor, he probado todo lo que he visto aquí en la pila y en general en Google, pero SimonTest siempre me dice que esta función no está probada.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Dado que displayBadge() está devolviendo el valor que está probando, algo como esto debería funcionar:

 it('text aaaaa', () => { expect(component.displayBadge('aaaaa')).toEqual('badge badge-pill badge-secondary'); });
over 4 years ago · Santiago Trujillo 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!