UNPKG

test-fns

Version:

write usecase driven tests systematically for simpler, safer, and more readable code

60 lines (59 loc) 2.54 kB
export declare const getNumberRange: (input: { start: number; end: number; }) => number[]; type TestContextShape = Record<string, any> | void; type TestInputWithReason<TContext extends Record<string, any> | void> = [ string, { because: string; }, (context: TContext) => Promise<void> | void ]; type TestInputWithoutReason<TContext extends Record<string, any> | void> = [string, (context: TContext) => Promise<void> | void] | [string]; type TestInput<TContext extends TestContextShape> = TestInputWithReason<TContext> | TestInputWithoutReason<TContext>; interface Describe { (desc: string, fn: () => void): void; /** Only runs the tests inside this `describe` for the current file */ only: (desc: string, fn: () => void) => void; /** Skips running the tests inside this `describe` for the current file */ skip: (desc: string, fn: () => void) => void; /** Skips running the tests inside this `describe` for the current file if the condition is satisfied */ skipIf: (condition: boolean) => (desc: string, fn: () => void) => void; /** Runs the tests inside this `describe` for the current file only if the condition is satisfied */ runIf: (condition: boolean) => (desc: string, fn: () => void) => void; } interface Test { (...input: TestInput<void>): void; /** Only runs this test for the current file */ only: (...input: TestInput<void>) => void; /** Skips running this test */ skip: (...input: TestInput<void>) => void; /** Marks the test as one that still needs to be written */ todo: (...input: TestInput<void>) => void; /** Skips running the test, if the condition is satisfied */ skipIf: (condition: boolean) => (...input: TestInput<void>) => void; /** Runs the test if the condition is satisfied */ runIf: (condition: boolean) => (...input: TestInput<void>) => void; /** Runs the test repeatedly to evaluate repeatability */ repeatably: (configuration: { /** * how many attempts to run the test, repeatedly */ attempts: number; /** * the criteria for the whole test suite * * note * - EVERY = every test must pass for the suite to pass * - SOME = some test must pass for the suite to pass */ criteria: 'EVERY' | 'SOME'; }) => (...input: TestInput<{ attempt: number; }>) => void; } export declare const given: Describe; export declare const when: Describe; export declare const then: Test; export {};