Skip to content

Commit

Permalink
fix: fixed typescript error when calling assertion (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Feb 9, 2022
1 parent bf079d2 commit 4aa09c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/vitest/src/index.ts
Expand Up @@ -122,15 +122,15 @@ declare global {

// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore build namspace conflict
type VitestAssertion<A> = {
type VitestAssertion<A, T> = {
[K in keyof A]: A[K] extends Chai.Assertion
? Assertion<any>
? Assertion<T>
: A[K] extends (...args: any[]) => any
? A[K] // not converting function since they may contain overload
: VitestAssertion<A[K]>
}
: VitestAssertion<A[K], T>
} & ((type: string, message?: string) => Assertion)

interface Assertion<T = any> extends VitestAssertion<Chai.Assertion>, JestAssertion<T> {
interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T> {
resolves: Promisify<Assertion<T>>
rejects: Promisify<Assertion<T>>
}
Expand Down
6 changes: 6 additions & 0 deletions test/core/test/basic.test.ts
Expand Up @@ -25,6 +25,12 @@ test('JSON', () => {
assert.deepEqual(JSON.parse(output), input, 'matches original')
})

test('assertion is callable', () => {
const str = '13'
expect(str).to.be.a('string')
expect(str).not.to.be.a('number')
})

const hi = suite('suite')

hi.test('expect truthy', () => {
Expand Down

0 comments on commit 4aa09c8

Please sign in to comment.