Check a date with Chai
•
You need to check a date using Chai. You also need to account for the test execution time.
Compare the milliseconds using Chai’s closeTo
method.
const updatedAt = new Date()
// Some time later...
expect(updatedAt.getTime()).to.be.closeTo(Date.now(), 100)
The second closeTo
parameter controls the delta; the largest acceptable difference between the two values.
Sign up for my newsletter
A monthly round-up of blog posts, projects, and internet oddments.