fix(assertion-matchers): Refactor matcher implementations to consistently use customAssertion for improved consistency and clarity.
This commit is contained in:
@ -288,6 +288,49 @@ export class Assertion<T = unknown> {
|
||||
console.log(`Path: ${this.formatDrillDown() || '(root)'}`);
|
||||
return this;
|
||||
}
|
||||
// Direct (flat) matcher aliases
|
||||
public toEqual(expected: any) {
|
||||
return this.customAssertion(
|
||||
(v) => plugins.fastDeepEqual(v, expected),
|
||||
`Expected value to equal ${JSON.stringify(expected)}`
|
||||
);
|
||||
}
|
||||
public toBeTrue() { return this.boolean.toBeTrue(); }
|
||||
public toBeFalse() { return this.boolean.toBeFalse(); }
|
||||
public toBeTruthy() { return this.boolean.toBeTruthy(); }
|
||||
public toBeFalsy() { return this.boolean.toBeFalsy(); }
|
||||
public toThrow(expectedError?: any) { return this.function.toThrow(expectedError); }
|
||||
public toBeGreaterThan(value: number) { return this.number.toBeGreaterThan(value); }
|
||||
public toBeLessThan(value: number) { return this.number.toBeLessThan(value); }
|
||||
public toBeGreaterThanOrEqual(value: number) { return this.number.toBeGreaterThanOrEqual(value); }
|
||||
public toBeLessThanOrEqual(value: number) { return this.number.toBeLessThanOrEqual(value); }
|
||||
public toBeCloseTo(value: number, precision?: number) { return this.number.toBeCloseTo(value, precision); }
|
||||
public toBeArray() { return this.array.toBeArray(); }
|
||||
public toContain(item: any) { return this.array.toContain(item); }
|
||||
public toContainEqual(item: any) { return this.array.toContainEqual(item); }
|
||||
public toContainAll(items: any[]) { return this.array.toContainAll(items); }
|
||||
public toExclude(item: any) { return this.array.toExclude(item); }
|
||||
public toBeEmptyArray() { return this.array.toBeEmptyArray(); }
|
||||
public toStartWith(prefix: string) { return this.string.toStartWith(prefix); }
|
||||
public toEndWith(suffix: string) { return this.string.toEndWith(suffix); }
|
||||
public toInclude(substring: string) { return this.string.toInclude(substring); }
|
||||
public toMatch(regex: RegExp) { return this.string.toMatch(regex); }
|
||||
public toBeOneOf(values: any[]) { return this.string.toBeOneOf(values as string[]); }
|
||||
public toHaveProperty(property: string, value?: any) { return this.object.toHaveProperty(property, value); }
|
||||
public toMatchObject(expected: object) { return this.object.toMatchObject(expected); }
|
||||
public toBeInstanceOf(constructor: any) { return this.object.toBeInstanceOf(constructor); }
|
||||
public toHaveDeepProperty(path: string[]) { return this.object.toHaveDeepProperty(path); }
|
||||
public toBeNull() { return this.object.toBeNull(); }
|
||||
public toBeUndefined() { return this.object.toBeUndefined(); }
|
||||
public toBeNullOrUndefined() { return this.object.toBeNullOrUndefined(); }
|
||||
public toBeDate() { return this.date.toBeDate(); }
|
||||
public toBeBeforeDate(date: Date) { return this.date.toBeBeforeDate(date); }
|
||||
public toBeAfterDate(date: Date) { return this.date.toBeAfterDate(date); }
|
||||
public toBeTypeofString() { return this.type.toBeTypeofString(); }
|
||||
public toBeTypeofNumber() { return this.type.toBeTypeofNumber(); }
|
||||
public toBeTypeofBoolean() { return this.type.toBeTypeofBoolean(); }
|
||||
public toBeTypeOf(typeName: string) { return this.type.toBeTypeOf(typeName); }
|
||||
public toBeDefined() { return this.type.toBeDefined(); }
|
||||
// Namespaced matcher accessors
|
||||
/** String-specific matchers */
|
||||
public get string() {
|
||||
|
Reference in New Issue
Block a user