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(tests): cut duplicate error in negated toHaveBeenCalled #2638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
],
)
if (called && isNot)
msg += formatCalls(spy, msg)
msg = formatCalls(spy, msg)

if ((called && isNot) || (!called && !isNot)) {
const err = new Error(msg)
Expand All @@ -443,7 +443,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
)

if ((pass && isNot) || (!pass && !isNot)) {
msg += formatCalls(spy, msg, args)
msg = formatCalls(spy, msg, args)
const err = new Error(msg)
err.name = 'AssertionError'
throw err
Expand Down
26 changes: 26 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,32 @@ describe('toSatisfy()', () => {
})
})

describe('toHaveBeenCalled', () => {
describe('negated', () => {
it('fails if called', () => {
const mock = vi.fn()
mock()

expect(() => {
expect(mock).not.toHaveBeenCalled()
}).toThrow(/^expected "spy" to not be called at all[^e]/)
})
})
})

describe('toHaveBeenCalledWith', () => {
describe('negated', () => {
it('fails if called', () => {
const mock = vi.fn()
mock(3)

expect(() => {
expect(mock).not.toHaveBeenCalledWith(3)
}).toThrow(/^expected "spy" to not be called with arguments: \[ 3 \][^e]/)
})
})
})

describe('async expect', () => {
it('resolves', async () => {
await expect((async () => 'true')()).resolves.toBe('true')
Expand Down