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

213
Views
Error al comparar la fecha en la prueba con jazmín

Tengo un error al comparar "fecha" en una prueba en Angular. El test muestra el error pero en el propio log es correcto.

mi prueba:

 it('myTest', () => { const today = new Date(); component.minDate = null; component.maxDate = null; spyOnProperty(component, 'isRange').and.returnValue(false); component['setActivateDate'](null); spyOn(component, <any>'verifyActivateDate').and.callThrough(); expect(component.activateDate).toEqual(today); });

Iniciar sesión con "error"

 Error: Expected Date(Wed Nov 17 2021 20:28:54 GMT+0000 (Coordinated Universal Time)) to equal Date(Wed Nov 17 2021 20:28:54 GMT+0000 (Coordinated Universal Time)). at <Jasmine>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Las fechas que está comparando parecen iguales ya que la representación de cadena solo presenta el valor al segundo. Sus fechas son iguales hasta ese momento, pero difieren en el rango de milisegundos, que no se muestra (pero forma parte de la verificación de igualdad).

Puede usar una biblioteca (por ejemplo, dayjs) para la comparación, o puede implementar una verificación "casi igual".

 // Pass the dates you want to compare and an "accuracy" value. // The accuracy removes that number of digits from the timestamp, of // so the default value of "3" means "remove the last 3 digits", which // effectively means you are only comparing up until seconds const expectDatesToNearlyEqual = (d1: Date, d2: Date, accuracy: number = 3) => { // Timestamp of first date, removing "accuracy" amount of digits from the end const d1Time = Math.floor(+d1 / (accuracy * 10)); // Timestamp of second date, removing "accuracy" amount of digits from the end const d2Time = Math.floor(+d2 / (accuracy * 10)); // Expect the timestamps to equal, if they are not, print a nice message (optional). expect(d1Time).withContext(`${d1} and ${d2} are not equal`).toEqual(d2Time); }
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!