From 0b8e3bd2507bd9f1f036b75fe76ea91b89eb9d76 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 21 May 2022 18:24:20 +0200 Subject: [PATCH 1/4] test: add failing test --- test/core/test/jest-expect.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index f534bba158d6..6473ee98a80d 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -429,6 +429,10 @@ describe('toSatisfy()', () => { it('pass with negotiation', () => { expect(2).not.toSatisfy(isOdd) }) + + it.fails('fail with missing negotiation', () => { + expect(2).toSatisfy(isOdd) + }) }) describe('async expect', () => { From 75f16fc4012c775062193d0b254e42bdf9b15668 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 21 May 2022 18:25:52 +0200 Subject: [PATCH 2/4] fix: toSatisfy never executes the matcher function --- packages/vitest/src/integrations/chai/jest-expect.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vitest/src/integrations/chai/jest-expect.ts b/packages/vitest/src/integrations/chai/jest-expect.ts index dfc7559a9a87..ca1858721cae 100644 --- a/packages/vitest/src/integrations/chai/jest-expect.ts +++ b/packages/vitest/src/integrations/chai/jest-expect.ts @@ -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) { From 04891ab631b832705d17384c343d082e9a59a90c Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 21 May 2022 18:29:48 +0200 Subject: [PATCH 3/4] test: ensure that the matcher function gets called --- test/core/test/jest-expect.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index 6473ee98a80d..bc4027faab5b 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -433,6 +433,13 @@ describe('toSatisfy()', () => { 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', () => { From 9b1323cdce644ed744bd344779c16bc3cb7ce0da Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 21 May 2022 18:44:19 +0200 Subject: [PATCH 4/4] test: fix missing imports --- test/core/test/jest-expect.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index bc4027faab5b..7c150c8f8c2c 100644 --- a/test/core/test/jest-expect.test.ts +++ b/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 {}