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

197
Views
Jasmine Unit probando una función que utiliza la consulta de documentos

Necesito ayuda para aumentar la cobertura de mi código. Tengo esta función en mi archivo ts y necesito entender cómo hacer que se ejecute esta instrucción if.

 setWidth(): void { let maxHeight = 0; document.querySelectorAll<HTMLElement>(`.body`).forEach(element => { if (element.offsetHeight > maxHeight){ maxHeight = element.offsetHeight; } });

No tengo claro cómo haría que forEach se ejecutara en mi archivo spec.ts.

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

0

Prueba esto:

 it('should set maxHeight', () => { // set a spy and return a mocked array. // add as any here below as well. spyOn(document, 'querySelectorAll').and.returnValue([{ offsetHeight: 20 }] as any); service.setWidth(); // below is a bad expectation but I am not sure what to expect for you from the // code provided. Do an assertion that relates to setWidth. expect(1).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!