mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
[@types/jest]: improve definition of MatcherUtils (#40068)
* [@types/jest]: improve definition of MatcherUtils * Update `equals` types
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
a872962928
commit
1d5494e2a9
Vendored
+67
-15
@@ -424,38 +424,90 @@ declare namespace jest {
|
||||
each: Each;
|
||||
}
|
||||
|
||||
type PrintLabel = (string: string) => string;
|
||||
|
||||
type MatcherHintColor = (arg: string) => string;
|
||||
|
||||
interface MatcherHintOptions {
|
||||
comment?: string;
|
||||
expectedColor?: MatcherHintColor;
|
||||
isDirectExpectCall?: boolean;
|
||||
isNot?: boolean;
|
||||
promise?: string;
|
||||
receivedColor?: MatcherHintColor;
|
||||
secondArgument?: string;
|
||||
secondArgumentColor?: MatcherHintColor;
|
||||
}
|
||||
|
||||
interface ChalkFunction {
|
||||
(text: TemplateStringsArray, ...placeholders: any[]): string;
|
||||
(...text: any[]): string;
|
||||
}
|
||||
|
||||
interface ChalkColorSupport {
|
||||
level: 0 | 1 | 2 | 3;
|
||||
hasBasic: boolean;
|
||||
has256: boolean;
|
||||
has16m: boolean;
|
||||
}
|
||||
|
||||
type MatcherColorFn = ChalkFunction & { supportsColor: ChalkColorSupport };
|
||||
|
||||
type EqualityTester = (a: any, b: any) => boolean | undefined;
|
||||
|
||||
interface MatcherUtils {
|
||||
readonly isNot: boolean;
|
||||
readonly dontThrow: () => void;
|
||||
readonly promise: string;
|
||||
readonly assertionCalls: number;
|
||||
readonly expectedAssertionsNumber: number | null;
|
||||
readonly isExpectingAssertions: boolean;
|
||||
readonly suppressedErrors: any[];
|
||||
readonly expand: boolean;
|
||||
readonly testPath: string;
|
||||
readonly currentTestName: string;
|
||||
utils: {
|
||||
readonly EXPECTED_COLOR: (text: string) => string;
|
||||
readonly RECEIVED_COLOR: (text: string) => string;
|
||||
diff: typeof import('jest-diff');
|
||||
ensureActualIsNumber(actual: any, matcherName?: string): void;
|
||||
ensureExpectedIsNumber(actual: any, matcherName?: string): void;
|
||||
ensureNoExpected(actual: any, matcherName?: string): void;
|
||||
ensureNumbers(actual: any, expected: any, matcherName?: string): void;
|
||||
/**
|
||||
* get the type of a value with handling of edge cases like `typeof []` and `typeof null`
|
||||
*/
|
||||
getType(value: any): string;
|
||||
readonly EXPECTED_COLOR: MatcherColorFn;
|
||||
readonly RECEIVED_COLOR: MatcherColorFn;
|
||||
readonly INVERTED_COLOR: MatcherColorFn;
|
||||
readonly BOLD_WEIGHT: MatcherColorFn;
|
||||
readonly DIM_COLOR: MatcherColorFn;
|
||||
readonly SUGGEST_TO_CONTAIN_EQUAL: string;
|
||||
diff(a: any, b: any, options?: import("jest-diff").DiffOptions): string | null;
|
||||
ensureActualIsNumber(actual: any, matcherName: string, options?: MatcherHintOptions): void;
|
||||
ensureExpectedIsNumber(actual: any, matcherName: string, options?: MatcherHintOptions): void;
|
||||
ensureNoExpected(actual: any, matcherName: string, options?: MatcherHintOptions): void;
|
||||
ensureNumbers(actual: any, expected: any, matcherName: string, options?: MatcherHintOptions): void;
|
||||
ensureExpectedIsNonNegativeInteger(expected: any, matcherName: string, options?: MatcherHintOptions): void;
|
||||
matcherHint(
|
||||
matcherName: string,
|
||||
received?: string,
|
||||
expected?: string,
|
||||
options?: { secondArgument?: string; isDirectExpectCall?: boolean }
|
||||
options?: MatcherHintOptions
|
||||
): string;
|
||||
matcherErrorMessage(
|
||||
hint: string,
|
||||
generic: string,
|
||||
specific: string
|
||||
): string;
|
||||
pluralize(word: string, count: number): string;
|
||||
printReceived(object: any): string;
|
||||
printExpected(value: any): string;
|
||||
printReceived(value: any): string;
|
||||
printWithType(name: string, received: any, print: (value: any) => string): string;
|
||||
printWithType(name: string, value: any, print: (value: any) => string): string;
|
||||
stringify(object: {}, maxDepth?: number): string;
|
||||
highlightTrailingWhitespace(text: string): string;
|
||||
|
||||
printDiffOrStringify(expected: any, received: any, expectedLabel: string, receivedLabel: string, expand: boolean): string;
|
||||
|
||||
getLabelPrinter(...strings: string[]): PrintLabel;
|
||||
|
||||
iterableEquality: EqualityTester;
|
||||
subsetEquality: EqualityTester;
|
||||
};
|
||||
/**
|
||||
* This is a deep-equality function that will return true if two objects have the same values (recursively).
|
||||
*/
|
||||
equals(a: any, b: any): boolean;
|
||||
equals(a: any, b: any, customTesters?: EqualityTester[], strictCheck?: boolean): boolean;
|
||||
[other: string]: any;
|
||||
}
|
||||
|
||||
|
||||
@@ -725,22 +725,16 @@ expect.extend({
|
||||
const expectedColor = this.utils.EXPECTED_COLOR('blue');
|
||||
const receivedColor = this.utils.EXPECTED_COLOR('red');
|
||||
|
||||
const diff: string = this.utils.diff({}, {});
|
||||
const diff: string | null = this.utils.diff({}, {});
|
||||
|
||||
this.utils.ensureActualIsNumber({});
|
||||
this.utils.ensureActualIsNumber({}, 'matcher');
|
||||
|
||||
this.utils.ensureExpectedIsNumber({});
|
||||
this.utils.ensureExpectedIsNumber({}, 'matcher');
|
||||
|
||||
this.utils.ensureNoExpected({});
|
||||
this.utils.ensureNoExpected({}, 'matcher');
|
||||
|
||||
this.utils.ensureNumbers({}, {});
|
||||
this.utils.ensureNumbers({}, {}, 'matcher');
|
||||
|
||||
const valueType: string = this.utils.getType({});
|
||||
|
||||
this.utils.matcherHint('matcher');
|
||||
this.utils.matcherHint('matcher', 'received');
|
||||
this.utils.matcherHint('matcher', 'received', 'expected');
|
||||
|
||||
Reference in New Issue
Block a user