UNPKG

jest-test-each

Version:

run parametrised tests easily [typesafe] without text tables or arrays of arrays.

57 lines (56 loc) 2.37 kB
/// <reference types="jest" /> import { TestSetupType } from './test-each-setup'; import JestMatchers = jest.JestMatchers; import { CaseAddition, WithDesc } from './types'; declare type InputCaseType<T> = T & (WithDesc | WithComplexDesc<T>) & CaseAddition; declare type Disposable = { dispose?: () => void; }; declare type SimpleCase<T> = InputCaseType<T>; declare type FuncCase<T, TOut> = (t: T) => SimpleCase<TOut[]>; declare type Input<T, TOut> = SimpleCase<TOut>[] | FuncCase<T, TOut>; declare type DescFunc<T> = (k: T) => string; declare type WithComplexDesc<T> = { desc?: string | DescFunc<T>; }; declare type InputFilter<T> = (t: T) => boolean; declare type Before<T> = T & Disposable; declare type BeforeOut<T> = Promise<Before<T>> | Before<T>; declare type BeforeInput<T, TOut> = (t: T) => BeforeOut<TOut> | void; export declare class TestEach<Combined extends CaseAddition = {}, BeforeT = {}> { private groups; private befores; private ensures; private ensuresCasesLength; private conf; private defects; private skippedTest; private onlyOne; private concurrentTests; private onlyOneFilter; private flatDescFunc; private readonly testParentDesc; private readonly env; constructor(desc: string | undefined); only(input?: InputFilter<Combined>): TestEach<Combined, BeforeT>; config(config: Partial<TestSetupType>): TestEach<Combined, BeforeT>; concurrent(): TestEach<Combined, BeforeT>; ensure(desc: string, cases: (t: Combined[]) => void): TestEach<Combined, BeforeT>; ensureCasesLength(exp: (t: JestMatchers<number>) => void): TestEach<Combined, BeforeT>; defect(reason: string, input?: InputFilter<Combined>, actualFailReasons?: string[]): TestEach<Combined, BeforeT>; skip(reason: string): TestEach<Combined, BeforeT>; desc(input: DescFunc<Combined>): TestEach<Combined, BeforeT>; before<TOut>(before: BeforeInput<Combined, TOut>): TestEach<Combined, BeforeT & TOut>; each<TOut>(cases: Input<Combined, TOut>): TestEach<Combined & TOut, BeforeT>; private runTest; private runBody; private entityName; private runCase; private testIfOnly; private findDefect; private runIsDefectExist; private filterAndRunIfSearchFailed; private runEnsures; run(body: (each: Combined, before: BeforeT) => void): void; } export {};