Skip to content

Commit

Permalink
fix: toSatisfy never executes the matcher function (#1350)
Browse files Browse the repository at this point in the history
* test: add failing test

* fix: toSatisfy never executes the matcher function

* test: ensure that the matcher function gets called

* test: fix missing imports
  • Loading branch information
ST-DDT committed May 21, 2022
1 parent fbaa546 commit 5654a88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit 5654a88

Please sign in to comment.