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: toSatisfy never executes the matcher function #1350

Merged
merged 4 commits into from May 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/chai/jest-expect.ts
Expand Up @@ -575,8 +575,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
callResult,
)
})
def('toSatisfy', function () {
return this.be.satisfy
def('toSatisfy', function (matcher: Function, message?: string) {
return this.be.satisfy(matcher, message)
})

utils.addProperty(chai.Assertion.prototype, 'resolves', function __VITEST_RESOLVES__(this: any) {
Expand Down
13 changes: 12 additions & 1 deletion test/core/test/jest-expect.test.ts
@@ -1,6 +1,6 @@
/* eslint-disable comma-spacing */
/* eslint-disable no-sparse-arrays */
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'

class TestError extends Error {}

Expand Down Expand Up @@ -429,6 +429,17 @@ describe('toSatisfy()', () => {
it('pass with negotiation', () => {
expect(2).not.toSatisfy(isOdd)
})

it.fails('fail with missing negotiation', () => {
expect(2).toSatisfy(isOdd)
})

it('calls the function', () => {
const isOddMock = vi.fn(isOdd)
expect(isOddMock).not.toBeCalled()
expect(1).toSatisfy(isOddMock)
expect(isOddMock).toBeCalled()
})
})

describe('async expect', () => {
Expand Down