From 9cdd616dd868bdcbfe51fac1d232d9c57a872950 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 9 Feb 2022 08:37:59 +0300 Subject: [PATCH 1/6] fix: fixed typescript error when calling assertion --- packages/vitest/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/index.ts b/packages/vitest/src/index.ts index 0801dd93bc38..e08a72c038aa 100644 --- a/packages/vitest/src/index.ts +++ b/packages/vitest/src/index.ts @@ -128,7 +128,7 @@ declare global { : A[K] extends (...args: any[]) => any ? A[K] // not converting function since they may contain overload : VitestAssertion - } + } & ((type: string, message?: string) => void) interface Assertion extends VitestAssertion, JestAssertion { resolves: Promisify> From f3d93ca9e131e572c60441927276a56819a7f6ec Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 9 Feb 2022 08:44:34 +0300 Subject: [PATCH 2/6] chore: fix return type of callable assertion --- packages/vitest/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/index.ts b/packages/vitest/src/index.ts index e08a72c038aa..293f59fd954e 100644 --- a/packages/vitest/src/index.ts +++ b/packages/vitest/src/index.ts @@ -128,7 +128,7 @@ declare global { : A[K] extends (...args: any[]) => any ? A[K] // not converting function since they may contain overload : VitestAssertion - } & ((type: string, message?: string) => void) + } & ((type: string, message?: string) => Assertion) interface Assertion extends VitestAssertion, JestAssertion { resolves: Promisify> From af5abad3cf2e92a07b5d7732fa10caed229b507d Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 9 Feb 2022 08:52:56 +0300 Subject: [PATCH 3/6] test: add test for to.be is callable --- test/core/test/basic.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/core/test/basic.test.ts b/test/core/test/basic.test.ts index b646ce3220e4..e66fefd81068 100644 --- a/test/core/test/basic.test.ts +++ b/test/core/test/basic.test.ts @@ -1,4 +1,5 @@ import { assert, expect, it, suite, test } from 'vitest' +import { expect as chaiExpect } from 'chai' import { two } from '../src/submodule' import { timeout } from '../src/timeout' @@ -25,6 +26,13 @@ test('JSON', () => { assert.deepEqual(JSON.parse(output), input, 'matches original') }) +test('assertion is callable', () => { + const str = '13' + chaiExpect(str).to.be('13') + expect(str).to.be('13') + expect(str).not.to.be('12') +}) + const hi = suite('suite') hi.test('expect truthy', () => { From c162e0e4509a104c16aa3516f54c19311a2814fa Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 9 Feb 2022 08:53:11 +0300 Subject: [PATCH 4/6] fix: inherit assertion generic --- packages/vitest/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vitest/src/index.ts b/packages/vitest/src/index.ts index 293f59fd954e..35db361a9f94 100644 --- a/packages/vitest/src/index.ts +++ b/packages/vitest/src/index.ts @@ -122,15 +122,15 @@ declare global { // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error // @ts-ignore build namspace conflict - type VitestAssertion = { + type VitestAssertion = { [K in keyof A]: A[K] extends Chai.Assertion - ? Assertion + ? Assertion : A[K] extends (...args: any[]) => any ? A[K] // not converting function since they may contain overload - : VitestAssertion + : VitestAssertion } & ((type: string, message?: string) => Assertion) - interface Assertion extends VitestAssertion, JestAssertion { + interface Assertion extends VitestAssertion, JestAssertion { resolves: Promisify> rejects: Promisify> } From 273e448ecfb2c33f9993132f9c06269d065b7696 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 9 Feb 2022 08:59:36 +0300 Subject: [PATCH 5/6] chore: remove non existent import --- test/core/test/basic.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/core/test/basic.test.ts b/test/core/test/basic.test.ts index e66fefd81068..0d8cce2d6415 100644 --- a/test/core/test/basic.test.ts +++ b/test/core/test/basic.test.ts @@ -1,5 +1,4 @@ import { assert, expect, it, suite, test } from 'vitest' -import { expect as chaiExpect } from 'chai' import { two } from '../src/submodule' import { timeout } from '../src/timeout' @@ -28,7 +27,6 @@ test('JSON', () => { test('assertion is callable', () => { const str = '13' - chaiExpect(str).to.be('13') expect(str).to.be('13') expect(str).not.to.be('12') }) From cb7695c0407355fbc5231265d3bfe7fe234e17ee Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 9 Feb 2022 09:18:49 +0300 Subject: [PATCH 6/6] chore: fix assertion test --- test/core/test/basic.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/core/test/basic.test.ts b/test/core/test/basic.test.ts index 0d8cce2d6415..dad3e931880c 100644 --- a/test/core/test/basic.test.ts +++ b/test/core/test/basic.test.ts @@ -27,8 +27,8 @@ test('JSON', () => { test('assertion is callable', () => { const str = '13' - expect(str).to.be('13') - expect(str).not.to.be('12') + expect(str).to.be.a('string') + expect(str).not.to.be.a('number') }) const hi = suite('suite')