feat(generics): Improve assertion and matcher type definitions by adding execution mode generics for better async/sync support

This commit is contained in:
2025-04-29 12:08:57 +00:00
parent 81bd8bfb13
commit 8cb70b6afe
12 changed files with 85 additions and 60 deletions

View File

@ -1,11 +1,12 @@
import { Assertion } from '../smartexpect.classes.assertion.js';
import * as plugins from '../plugins.js';
import type { TExecutionType } from '../types.js';
/**
* Namespace for array-specific matchers
*/
export class ArrayMatchers<T> {
constructor(private assertion: Assertion<T[]>) {}
export class ArrayMatchers<T, M extends TExecutionType> {
constructor(private assertion: Assertion<T[], M>) {}
toBeArray() {
return this.assertion.customAssertion(

View File

@ -1,10 +1,11 @@
import { Assertion } from '../smartexpect.classes.assertion.js';
import type { TExecutionType } from '../types.js';
/**
* Namespace for boolean-specific matchers
*/
export class BooleanMatchers {
constructor(private assertion: Assertion<boolean>) {}
export class BooleanMatchers<M extends TExecutionType> {
constructor(private assertion: Assertion<boolean, M>) {}
toBeTrue() {
return this.assertion.customAssertion(

View File

@ -1,10 +1,11 @@
import { Assertion } from '../smartexpect.classes.assertion.js';
import type { TExecutionType } from '../types.js';
/**
* Namespace for date-specific matchers
*/
export class DateMatchers {
constructor(private assertion: Assertion<Date>) {}
export class DateMatchers<M extends TExecutionType> {
constructor(private assertion: Assertion<Date, M>) {}
toBeDate() {
return this.assertion.customAssertion(

View File

@ -1,10 +1,11 @@
import { Assertion } from '../smartexpect.classes.assertion.js';
import type { TExecutionType } from '../types.js';
/**
* Namespace for function-specific matchers
*/
export class FunctionMatchers {
constructor(private assertion: Assertion<Function>) {}
export class FunctionMatchers<M extends TExecutionType> {
constructor(private assertion: Assertion<Function, M>) {}
toThrow(expectedError?: any) {
return this.assertion.customAssertion(

View File

@ -1,10 +1,11 @@
import { Assertion } from '../smartexpect.classes.assertion.js';
import type { TExecutionType } from '../types.js';
/**
* Namespace for number-specific matchers
*/
export class NumberMatchers {
constructor(private assertion: Assertion<number>) {}
export class NumberMatchers<M extends TExecutionType> {
constructor(private assertion: Assertion<number, M>) {}
toBeGreaterThan(value: number) {
return this.assertion.customAssertion(

View File

@ -1,11 +1,12 @@
import { Assertion, AnyMatcher, AnythingMatcher } from '../smartexpect.classes.assertion.js';
import type { TExecutionType } from '../types.js';
import * as plugins from '../plugins.js';
/**
* Namespace for object-specific matchers
*/
export class ObjectMatchers<T extends object> {
constructor(private assertion: Assertion<T>) {}
export class ObjectMatchers<T extends object, M extends TExecutionType> {
constructor(private assertion: Assertion<T, M>) {}
toEqual(expected: any) {
return this.assertion.customAssertion(

View File

@ -1,10 +1,11 @@
import { Assertion } from '../smartexpect.classes.assertion.js';
import type { TExecutionType } from '../types.js';
/**
* Namespace for string-specific matchers
*/
export class StringMatchers {
constructor(private assertion: Assertion<string>) {}
export class StringMatchers<M extends TExecutionType> {
constructor(private assertion: Assertion<string, M>) {}
toStartWith(prefix: string) {
return this.assertion.customAssertion(

View File

@ -1,10 +1,11 @@
import { Assertion } from '../smartexpect.classes.assertion.js';
import type { TExecutionType } from '../types.js';
/**
* Namespace for type-based matchers
*/
export class TypeMatchers {
constructor(private assertion: Assertion<any>) {}
export class TypeMatchers<M extends TExecutionType> {
constructor(private assertion: Assertion<any, M>) {}
toBeTypeofString() {
return this.assertion.customAssertion(