Skip to content

Commit

Permalink
fix: print actual number for toBeCalledTimes (#3696)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Jul 3, 2023
1 parent 80ea7ef commit d364043
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
const callCount = spy.mock.calls.length
return this.assert(
callCount === number,
`expected "${spyName}" to be called #{exp} times`,
`expected "${spyName}" to be called #{exp} times, but got ${callCount} times`,
`expected "${spyName}" to not be called #{exp} times`,
number,
callCount,
Expand All @@ -410,7 +410,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
const callCount = spy.mock.calls.length
return this.assert(
callCount === 1,
`expected "${spyName}" to be called once`,
`expected "${spyName}" to be called once, but got ${callCount} times`,
`expected "${spyName}" to not be called once`,
1,
callCount,
Expand All @@ -420,14 +420,15 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
def(['toHaveBeenCalled', 'toBeCalled'], function () {
const spy = getSpy(this)
const spyName = spy.getMockName()
const called = spy.mock.calls.length > 0
const callCount = spy.mock.calls.length
const called = callCount > 0
const isNot = utils.flag(this, 'negate') as boolean
let msg = utils.getMessage(
this,
[
called,
`expected "${spyName}" to be called at least once`,
`expected "${spyName}" to not be called at all`,
`expected "${spyName}" to not be called at all, but actually been called ${callCount} times`,
true,
called,
],
Expand Down

0 comments on commit d364043

Please sign in to comment.