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

192
Views
Parche mono de prueba unitaria en Angular (No se pueden leer las propiedades de undefined (leyendo 'checkABC'))

Estoy intentando realizar una prueba unitaria de mi método setStep () en angular usando Jasmine, pero sigo recibiendo Cannot read properties of undefined (reading 'checkBusiness') thrown lo que me impide continuar con la prueba.

Esta es la función en el componente.ts :

 get userBusiness(): string { return this.auth && this.auth.user && this.auth.user.Source; } setSteps() { if (this.userBusiness.checkBusiness('ABC')) { this.items = steps['ABC']; if (this.application.process.onboarding.status !== 'complete') { this.show = true; } } else { this.items = steps['DEF']; } }

El método checkBusiness() se define como un parche mono para la clase de prototipo String:

 Interface String { checkBusiness(...args: string[]): boolean; } String.prototype.checkBusiness = function(...args: string[]): boolean { let result = false; for (let arg of args) { const currentBusinessArray = business[this]; if (!currentBusinessArray) { result = false; continue; } if (currentBusinessArray.includes(arg)) { result = true; } } return result; };

Business es una matriz definida como:

 const lob = Object.freeze( <any> { ABC : ['ABC', 'ABC1', 'ABC2', 'ABC3'], DEF : ['DEF', 'DEF1', 'DEF2', 'DEF3'] });

Prueba/archivo de especificaciones :

 it('should confirm that "show" is set to true in setSteps()', () => { const testUserBusiness = {...testDataSvc.userABC} const userBusinessSpy = spyOnProperty(component, 'userBusiness').and.returnValue(testUserBusiness); console.log(component['userBusiness']); component.setSteps(); })

Problema: Sigo recibiendo Cannot read properties of undefined (reading 'checkBusiness') thrown

¿Alguna idea de cómo superar esto? He intentado buscar en todas partes, pero no hay algo como este escenario que pueda seguir.

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!