Skip to content

Commit 41e11da

Browse files
authoredMay 19, 2023
fix(spy): don't print received calls if there are no calls (#3405)
1 parent 6433224 commit 41e11da

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
 

‎packages/expect/src/jest-expect.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,18 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
353353
return `${i}th`
354354
}
355355
const formatCalls = (spy: EnhancedSpy, msg: string, actualCall?: any) => {
356-
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
357-
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
358-
if (actualCall)
359-
methodCall += diff(actualCall, callArg, { showLegend: false })
360-
else
361-
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')
362-
363-
methodCall += '\n'
364-
return methodCall
365-
}).join('\n')}`)
356+
if (spy.mock.calls) {
357+
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
358+
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
359+
if (actualCall)
360+
methodCall += diff(actualCall, callArg, { showLegend: false })
361+
else
362+
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')
363+
364+
methodCall += '\n'
365+
return methodCall
366+
}).join('\n')}`)
367+
}
366368
msg += c().gray(`\n\nNumber of calls: ${c().bold(spy.mock.calls.length)}\n`)
367369
return msg
368370
}

0 commit comments

Comments
 (0)
Please sign in to comment.