29 lines
775 B
TypeScript
29 lines
775 B
TypeScript
import { Assertion } from '../smartexpect.classes.assertion.js';
|
|
|
|
/**
|
|
* Namespace for date-specific matchers
|
|
*/
|
|
export class DateMatchers {
|
|
constructor(private assertion: Assertion<Date>) {}
|
|
|
|
toBeDate() {
|
|
return this.assertion.customAssertion(
|
|
(v) => v instanceof Date,
|
|
`Expected value to be a Date instance`
|
|
);
|
|
}
|
|
|
|
toBeBeforeDate(date: Date) {
|
|
return this.assertion.customAssertion(
|
|
(v) => v instanceof Date && (v as Date).getTime() < date.getTime(),
|
|
`Expected date to be before ${date.toISOString()}`
|
|
);
|
|
}
|
|
|
|
toBeAfterDate(date: Date) {
|
|
return this.assertion.customAssertion(
|
|
(v) => v instanceof Date && (v as Date).getTime() > date.getTime(),
|
|
`Expected date to be after ${date.toISOString()}`
|
|
);
|
|
}
|
|
} |