Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: print actual number for toBeCalledTimes #3696

Merged
merged 1 commit into from Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/expect/src/jest-expect.ts
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