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

Function ensureExpectedIsNonNegativeInteger

packages/jest-matcher-utils/src/index.ts:230–250  ·  view source on GitHub ↗
(
  expected: unknown,
  matcherName: string,
  options?: MatcherHintOptions,
)

Source from the content-addressed store, hash-verified

228};
229
230export const ensureExpectedIsNonNegativeInteger = (
231 expected: unknown,
232 matcherName: string,
233 options?: MatcherHintOptions,
234): void => {
235 if (
236 typeof expected !== 'number' ||
237 !Number.isSafeInteger(expected) ||
238 expected < 0
239 ) {
240 // Prepend maybe not only for backward compatibility.
241 const matcherString = (options ? '' : '[.not]') + matcherName;
242 throw new Error(
243 matcherErrorMessage(
244 matcherHint(matcherString, undefined, undefined, options),
245 `${EXPECTED_COLOR('expected')} value must be a non-negative integer`,
246 printWithType('Expected', expected, printExpected),
247 ),
248 );
249 }
250};
251
252// Given array of diffs, return concatenated string:
253// * include common substrings

Callers 3

toHaveLengthFunction · 0.90

Calls 3

matcherErrorMessageFunction · 0.85
matcherHintFunction · 0.85
printWithTypeFunction · 0.85

Tested by

no test coverage detected