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

Function isLineDiffableArg

packages/expect/src/spyMatchers.ts:272–311  ·  view source on GitHub ↗
(expected: unknown, received: unknown)

Source from the content-addressed store, hash-verified

270// Almost redundant with function in jest-matcher-utils,
271// except no line diff for any strings.
272const isLineDiffableArg = (expected: unknown, received: unknown): boolean => {
273 const expectedType = getType(expected);
274 const receivedType = getType(received);
275
276 if (expectedType !== receivedType) {
277 return false;
278 }
279
280 if (isPrimitive(expected)) {
281 return false;
282 }
283
284 if (
285 expectedType === 'date' ||
286 expectedType === 'function' ||
287 expectedType === 'regexp'
288 ) {
289 return false;
290 }
291
292 if (expected instanceof Error && received instanceof Error) {
293 return false;
294 }
295
296 if (
297 expectedType === 'object' &&
298 typeof (expected as any).asymmetricMatch === 'function'
299 ) {
300 return false;
301 }
302
303 if (
304 receivedType === 'object' &&
305 typeof (received as any).asymmetricMatch === 'function'
306 ) {
307 return false;
308 }
309
310 return true;
311};
312
313const printResult = (result: any, expected: unknown) =>
314 result.type === 'throw'

Callers 3

printDiffCallFunction · 0.85
isLineDiffableCallFunction · 0.85

Calls 2

getTypeFunction · 0.90
isPrimitiveFunction · 0.90

Tested by

no test coverage detected