MCPcopy
hub / github.com/jestjs/jest / printCloseTo

Function printCloseTo

packages/expect/src/print.ts:60–86  ·  view source on GitHub ↗
(
  receivedDiff: number,
  expectedDiff: number,
  precision: number,
  isNot: boolean | undefined,
)

Source from the content-addressed store, hash-verified

58 );
59
60export const printCloseTo = (
61 receivedDiff: number,
62 expectedDiff: number,
63 precision: number,
64 isNot: boolean | undefined,
65): string => {
66 const receivedDiffString = stringify(receivedDiff);
67 const expectedDiffString = receivedDiffString.includes('e')
68 ? // toExponential arg is number of digits after the decimal point.
69 expectedDiff.toExponential(0)
70 : 0 <= precision && precision < 20
71 ? // toFixed arg is number of digits after the decimal point.
72 // It may be a value between 0 and 20 inclusive.
73 // Implementations may optionally support a larger range of values.
74 expectedDiff.toFixed(precision + 1)
75 : stringify(expectedDiff);
76
77 return (
78 `Expected precision: ${isNot ? ' ' : ''} ${stringify(precision)}\n` +
79 `Expected difference: ${isNot ? 'not ' : ''}< ${EXPECTED_COLOR(
80 expectedDiffString,
81 )}\n` +
82 `Received difference: ${isNot ? ' ' : ''} ${RECEIVED_COLOR(
83 receivedDiffString,
84 )}`
85 );
86};
87
88export const printExpectedConstructorName = (
89 label: string,

Callers 1

toBeCloseToFunction · 0.90

Calls 1

stringifyFunction · 0.90

Tested by

no test coverage detected