64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
|
import NodeAssert from 'assert';
|
||
|
|
||
|
type ExtendedAssert = {
|
||
|
notOk(value: unknown, message?: string | Error): void,
|
||
|
match(value: string, test: RegExp, message?: string | Error): void,
|
||
|
notMatch(value: string, test: RegExp, message?: string | Error): void,
|
||
|
throwsAndCatch(fn: () => unknown, message?: string | Error): Error,
|
||
|
equalWithMargin(value: number, test: number, margin?: number, message?: string | Error): void,
|
||
|
isFulfilled<T>(promise: Promise<T>, message?: string | Error): Promise<T>,
|
||
|
isRejected(promise: Promise<unknown>, message?: string | Error): Promise<unknown>,
|
||
|
}
|
||
|
|
||
|
export const assert: typeof NodeAssert & ExtendedAssert
|
||
|
|
||
|
type Spy = {
|
||
|
(): unknown
|
||
|
lastCall: null | Array<unknown>
|
||
|
called: boolean
|
||
|
callCount: number
|
||
|
calls: Array<Array<unknown>>
|
||
|
findCall(fn: (args: Array<unknown>) => boolean): null | Array<unknown>
|
||
|
getCall(index: number): null | Array<unknown>
|
||
|
getCallN(index: number): null | Array<unknown>
|
||
|
onCall(index: number): Spy
|
||
|
onCallN(index: number): Spy
|
||
|
reset(): Spy
|
||
|
returns(data: unknown): Spy
|
||
|
throws(data: unknown): Spy
|
||
|
resolves(data: unknown): Spy
|
||
|
rejects(data: unknown): Spy
|
||
|
returnWith(fn: (...args: unknown[]) => unknown): Spy
|
||
|
}
|
||
|
|
||
|
export function spy(): Spy
|
||
|
export function stub(fun?: (...args: unknown[]) => unknown): Spy
|
||
|
|
||
|
type Test = {
|
||
|
timeout(timeout: number): void
|
||
|
skip(): void
|
||
|
only(): void
|
||
|
}
|
||
|
|
||
|
type TestResult = void | Promise<unknown>
|
||
|
|
||
|
type Callback = {
|
||
|
(): void
|
||
|
wrap(fn: () => unknown): void
|
||
|
finish(fn: () => unknown): void
|
||
|
}
|
||
|
|
||
|
type Eltro = {
|
||
|
before(fn: () => TestResult): Test
|
||
|
after(fn: () => TestResult): Test
|
||
|
beforeEach(fn: () => TestResult): Test
|
||
|
afterEachEach(fn: () => TestResult): Test
|
||
|
describe(name: string, fn: () => void)
|
||
|
timeout(timeout: number): Eltro
|
||
|
skip(): Eltro
|
||
|
only(): Eltro
|
||
|
test(name: string, func: (cb?: Callback) => TestResult): Test
|
||
|
}
|
||
|
|
||
|
export const Eltro: Eltro
|