Skip to content

Commit

Permalink
fix(spy): don't print received calls if there are no calls (#3405)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 19, 2023
1 parent 6433224 commit 41e11da
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/expect/src/jest-expect.ts
Expand Up @@ -353,16 +353,18 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
return `${i}th`
}
const formatCalls = (spy: EnhancedSpy, msg: string, actualCall?: any) => {
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
if (actualCall)
methodCall += diff(actualCall, callArg, { showLegend: false })
else
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')
methodCall += '\n'
return methodCall
}).join('\n')}`)
if (spy.mock.calls) {
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
if (actualCall)
methodCall += diff(actualCall, callArg, { showLegend: false })
else
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')
methodCall += '\n'
return methodCall
}).join('\n')}`)
}
msg += c().gray(`\n\nNumber of calls: ${c().bold(spy.mock.calls.length)}\n`)
return msg
}
Expand Down

0 comments on commit 41e11da

Please sign in to comment.