jeudi 15 novembre 2018

Node tests, how to compare object containing datetimes along with other properties?

You can use chai-datetime extension to compare date in chai with the regular chai assertion styles.

This allows you to do this:

const d1 = new Date('2018-01-01T00:00:00Z')
const d2 = new Date('2018-01-01T00:00:00Z')
expect(d1).to.equalDate(d2)

But how do you compare objects than contain a datetime other than other properties?

I want to compare

obj1 = {
  value: 'foo',
  datetime: new Date('2018-01-01T00:00:00Z')
}

and

obj2 = {
  value: 'foo',
  datetime: new Date('2018-01-01T00:00:00Z')
}

and have them being evaluated as equal. How do I do that?

Aucun commentaire:

Enregistrer un commentaire