forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chai.ts
63 lines (53 loc) · 1.84 KB
/
chai.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { use as chaiUse } from 'chai'
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import type * as jestMatcherUtils from '../integrations/chai/jest-matcher-utils'
import type SnapshotState from '../integrations/snapshot/port/state'
import type { VitestEnvironment } from './config'
export type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never
export type ChaiPlugin = FirstFunctionArgument<typeof chaiUse>
export type Tester = (a: any, b: any) => boolean | undefined
export interface MatcherState {
assertionCalls: number
currentTestName?: string
dontThrow?: () => void
error?: Error
equals: (
a: unknown,
b: unknown,
customTesters?: Array<Tester>,
strictCheck?: boolean,
) => boolean
expand?: boolean
expectedAssertionsNumber?: number | null
expectedAssertionsNumberErrorGen?: (() => Error) | null
isExpectingAssertions?: boolean
isExpectingAssertionsError?: Error | null
isNot: boolean
environment: VitestEnvironment
promise: string
snapshotState: SnapshotState
suppressedErrors: Array<Error>
testPath?: string
utils: typeof jestMatcherUtils & {
iterableEquality: Tester
subsetEquality: Tester
}
}
export interface SyncExpectationResult {
pass: boolean
message: () => string
actual?: any
expected?: any
}
export type AsyncExpectationResult = Promise<SyncExpectationResult>
export type ExpectationResult = SyncExpectationResult | AsyncExpectationResult
export interface RawMatcherFn<T extends MatcherState = MatcherState> {
(this: T, received: any, expected: any, options?: any): ExpectationResult
}
export type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>