UNPKG

@push.rocks/smartexpect

Version:

A testing library to manage expectations in code, offering both synchronous and asynchronous assertion methods.

30 lines (26 loc) 855 B
import { Assertion } from '../smartexpect.classes.assertion.js'; import type { TExecutionType } from '../types.js'; /** * Namespace for date-specific matchers */ export class DateMatchers<M extends TExecutionType> { constructor(private assertion: Assertion<Date, M>) {} 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()}` ); } }