-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
An assertion like
const expectedDate = ...;
const realDate = getDate();
expect(realDate).toBeSameHourAs(expectedDate); // Usually passcan fail in this circumstance:
const expectedDate = new Date('2022-12-29 8:59 AM');
const realDate = new Date('2022-12-29 9:00 AM');
expect(realDate).toBeSameHourAs(expectedDate); // FailsTo avoid unstable test assertions, I think an API like the following would be helpful:
expect(new Date('2022-12-29 8:59 AM')).toBeCloseTo(new Date('2022-12-29 9:00 AM')); // Pass
expect(new Date('2022-12-29 8:59 AM')).toBeCloseTo(new Date('2022-12-29 9:00 AM'), {
precision: 60_000, // Precision window in miliseconds
}); // Pass
expect(new Date('2022-12-29 8:59 AM')).toBeCloseTo(new Date('2022-12-29 9:00 AM'), {
precision: 1_000, // Precision window in miliseconds
}); // Faildouglascayers and jtomaszewski
Metadata
Metadata
Assignees
Labels
No labels