UNPKG

ts-bdd

Version:

A TypeScript BDD testing framework with typed shared examples and state management

46 lines 2.1 kB
type DescribeFn = (description: string, callback: () => void) => void; export type ItFn = (description: string, callback: () => void | Promise<void>) => void; type BeforeEachFn = (callback: () => void) => void; export interface TestRunner { describe: DescribeFn; beforeEach: BeforeEachFn; } export type State = Record<string, any>; export type Get<T extends State> = { <K extends keyof T>(key: K): T[K]; <K extends (keyof T)[]>(...keys: K): { [I in keyof K]: T[K[I]]; }; }; export type Set<T extends State> = <K extends keyof T>(key: K, valueFactory: () => T[K]) => void; export type ItBehavesLike<T extends Record<string, any>> = (name: keyof T) => void; export type SharedExampleCallback<TArg = void, TExamples extends Record<string, any> = {}, TState extends State = any> = TArg extends void ? (params: { subject: () => any; itBehavesLike: (name: keyof TExamples, ...args: any[]) => void; get?: Get<TState>; }) => void | Promise<void> : (arg: TArg, params: { subject: () => any; itBehavesLike: (name: keyof TExamples, ...args: any[]) => void; get?: Get<TState>; }) => void | Promise<void>; export type Lazy<T, S extends State> = (get: Get<S>) => T | Promise<T>; export type Definitions<T extends State> = { [K in keyof T]?: T[K] | Lazy<T[K], T>; }; export interface SharedExamplesBuilderWithBuild<T extends State, TExamples extends Record<string, any> = {}> { add<TName extends string, TArg = void>(name: TName, callback: SharedExampleCallback<TArg, TExamples, T>): SharedExamplesBuilderWithBuild<T, TExamples & Record<TName, typeof callback>>; build(): (name: keyof TExamples, ...args: any[]) => void; } export type ContextCallback = () => void; export type SuiteCallbackWithInlineBuilder<T extends State> = (params: { get: Get<T>; set: Set<T>; context: (description: string, callback: ContextCallback) => void; subject: { <V>(factory: () => V | Promise<V>): void; (): any; }; sharedExamplesBuilder: SharedExamplesBuilderWithBuild<T>; }) => void; export {}; //# sourceMappingURL=index.d.ts.map