hapijs / code

Assertion library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to compare objects that include timestamps

danielo515 opened this issue · comments

Hello,

I was wondering if there is a method to consider two objects to be equal if they include a timestamp which is close enough.

My problem comes when I generate the expected more or less manually, and both the expected and the actual object contains a timpestamp/date object that is generated when they are created. Of course there is a slight difference in milliseconds, but I want to consider them equal anyway.
Is there any mechanism or should I handle it manually ?

Regards

You can handle this manually pretty easily I think:

expect(Math.abs(d1.getTime() - d2.getTime())).to.be.lessThan(threshold);

Hello @cjihrig

What you said is the opposite of what I want. I want to compare two big objects, ignoring the timestamps which are just one or two properties. I don't want to comprare all the props one by one, neither delete the timestamp fields

Sorry, that's not what it sounded like, based on the original question.

There isn't really anything that does what you're asking for. There is include(), but you'll still end up specifying all of the parts of the object that you're interested in.

commented

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.