1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00
Files
browser/libs/common/spec/matchers/to-almost-equal.spec.ts
Carlos Gonçalves 0c0c2039ed Conflict resolution
2024-04-02 17:18:45 +01:00

55 lines
1.7 KiB
TypeScript

describe("toAlmostEqual custom matcher", () => {
it("matches identical Dates", () => {
const date = new Date();
expect(date).toAlmostEqual(date);
});
it("matches when older but within default ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() - 5);
expect(date).toAlmostEqual(olderDate);
});
it("matches when newer but within default ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() + 5);
expect(date).toAlmostEqual(olderDate);
});
it("doesn't match if older than default ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() - 11);
expect(date).not.toAlmostEqual(olderDate);
});
it("doesn't match if newer than default ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() + 11);
expect(date).not.toAlmostEqual(olderDate);
});
it("matches when older but within custom ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() - 15);
expect(date).toAlmostEqual(olderDate, 20);
});
it("matches when newer but within custom ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() + 15);
expect(date).toAlmostEqual(olderDate, 20);
});
it("doesn't match if older than custom ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() - 21);
expect(date).not.toAlmostEqual(olderDate, 20);
});
it("doesn't match if newer than custom ms", () => {
const date = new Date();
const olderDate = new Date(date.getTime() + 21);
expect(date).not.toAlmostEqual(olderDate, 20);
});
});