2025-04-28 19:10:27 +00:00
|
|
|
import { Assertion } from '../smartexpect.classes.assertion.js';
|
2025-04-29 12:08:57 +00:00
|
|
|
import type { TExecutionType } from '../types.js';
|
2025-04-28 19:10:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Namespace for date-specific matchers
|
|
|
|
*/
|
2025-04-29 12:08:57 +00:00
|
|
|
export class DateMatchers<M extends TExecutionType> {
|
|
|
|
constructor(private assertion: Assertion<Date, M>) {}
|
2025-04-28 19:10:27 +00:00
|
|
|
|
|
|
|
toBeDate() {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => v instanceof Date,
|
|
|
|
`Expected value to be a Date instance`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toBeBeforeDate(date: Date) {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => v instanceof Date && (v as Date).getTime() < date.getTime(),
|
|
|
|
`Expected date to be before ${date.toISOString()}`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toBeAfterDate(date: Date) {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => v instanceof Date && (v as Date).getTime() > date.getTime(),
|
|
|
|
`Expected date to be after ${date.toISOString()}`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
}
|