Skip to content

Commit

Permalink
chore: type printWithType more accurately (#12405)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 16, 2022
1 parent 943d823 commit 4f4538c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/jest-matcher-utils/src/index.ts
Expand Up @@ -136,19 +136,19 @@ export const printReceived = (object: unknown): string =>
export const printExpected = (value: unknown): string =>
EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));

export const printWithType = (
name: string, // 'Expected' or 'Received'
value: unknown,
print: (value: unknown) => string, // printExpected or printReceived
): string => {
export function printWithType<T>(
name: string,
value: T,
print: (value: T) => string,
): string {
const type = getType(value);
const hasType =
type !== 'null' && type !== 'undefined'
? `${name} has type: ${type}\n`
: '';
const hasValue = `${name} has value: ${print(value)}`;
return hasType + hasValue;
};
}

export const ensureNoExpected = (
expected: unknown,
Expand Down Expand Up @@ -511,8 +511,8 @@ export const matcherErrorMessage = (
// Old format: matcher name has dim color
export const matcherHint = (
matcherName: string,
received: string = 'received',
expected: string = 'expected',
received = 'received',
expected = 'expected',
options: MatcherHintOptions = {},
): string => {
const {
Expand Down

0 comments on commit 4f4538c

Please sign in to comment.