Skip to content

Commit

Permalink
fix: 🏷️ Use generic return type for all jest matchers (#655)
Browse files Browse the repository at this point in the history
This better aligns with jest documentation: https://archive.jestjs.io/docs/en/23.x/expect#expectextendmatchers and ensures that types can work properly with other jest extension libraries like jest-chain.
  • Loading branch information
pcbowers committed Apr 30, 2024
1 parent e427270 commit f322a65
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions projects/spectator/jest/src/lib/matchers-types.ts
@@ -1,59 +1,59 @@
declare namespace jest {
interface Matchers<R> {
toExist(): boolean;
toExist(): R;

toHaveLength(expected: number): boolean;
toHaveLength(expected: number): R;

toHaveId(id: string | number): boolean;
toHaveId(id: string | number): R;

toHaveClass(className: string | string[], options?: { strict: boolean }): boolean;
toHaveClass(className: string | string[], options?: { strict: boolean }): R;

toHaveAttribute(attr: string | object, val?: string): boolean;
toHaveAttribute(attr: string | object, val?: string): R;

toHaveProperty(prop: string | object, val?: string | boolean): boolean;
toHaveProperty(prop: string | object, val?: string | boolean): R;

toContainProperty(prop: string | object, val?: string): boolean;
toContainProperty(prop: string | object, val?: string): R;

toHaveText(text: string | string[] | ((text: string) => boolean), exact?: boolean): boolean;
toHaveText(text: string | string[] | ((text: string) => boolean), exact?: boolean): R;

toContainText(text: string | string[] | ((text: string) => boolean), exact?: boolean): boolean;
toContainText(text: string | string[] | ((text: string) => boolean), exact?: boolean): R;

toHaveExactText(text: string | string[] | ((text: string) => boolean), options?: { trim: boolean }): boolean;
toHaveExactText(text: string | string[] | ((text: string) => boolean), options?: { trim: boolean }): R;

toHaveExactTrimmedText(text: string | string[] | ((text: string) => boolean)): boolean;
toHaveExactTrimmedText(text: string | string[] | ((text: string) => boolean)): R;

toHaveValue(value: string | string[]): boolean;
toHaveValue(value: string | string[]): R;

toContainValue(value: string | string[]): boolean;
toContainValue(value: string | string[]): R;

toHaveStyle(style: { [styleKey: string]: any }): boolean;
toHaveStyle(style: { [styleKey: string]: any }): R;

toHaveData({ data, val }: { data: string; val: string }): boolean;
toHaveData({ data, val }: { data: string; val: string }): R;

toBeChecked(): boolean;
toBeChecked(): R;

toBeIndeterminate(): boolean;
toBeIndeterminate(): R;

toBeDisabled(): boolean;
toBeDisabled(): R;

toBeEmpty(): boolean;
toBeEmpty(): R;

toBePartial(partial: object): boolean;
toBePartial(partial: object): R;

toBeHidden(): boolean;
toBeHidden(): R;

toBeSelected(): boolean;
toBeSelected(): R;

toBeVisible(): boolean;
toBeVisible(): R;

toBeFocused(): boolean;
toBeFocused(): R;

toBeMatchedBy(selector: string | Element): boolean;
toBeMatchedBy(selector: string | Element): R;

toHaveDescendant(selector: string | Element): boolean;
toHaveDescendant(selector: string | Element): R;

toHaveDescendantWithText({ selector, text }: { selector: string; text: string }): boolean;
toHaveDescendantWithText({ selector, text }: { selector: string; text: string }): R;

toHaveSelectedOptions(expected: string | string[] | HTMLOptionElement | HTMLOptionElement[]): boolean;
toHaveSelectedOptions(expected: string | string[] | HTMLOptionElement | HTMLOptionElement[]): R;
}
}

0 comments on commit f322a65

Please sign in to comment.