UNPKG

@augment-vir/test

Version:

A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.

63 lines (62 loc) 1.8 kB
import { type AnyFunction } from '@augment-vir/core'; import { type FunctionTestCase } from './it-cases.js'; /** * Test case for {@link snapshotCases}. * * @category Test * @category Package : @augment-vir/test */ export type SnapshotTestCase<FunctionToTest extends AnyFunction> = Omit<FunctionTestCase<NoInfer<FunctionToTest>>, 'expect' | 'throws'> & { /** * If true, allows errors to be thrown and snapshotted. Otherwise thrown errors will fail the * test. */ fails?: boolean; }; /** * Similar to `itCases` but instead of defining expectation in each test case, each test case is a * snapshot test. * * In order to generate or update the snapshot files, run tests in update mode. * * @category Test * @category Package : @augment-vir/test * @example * * ```ts * import {snapshotCases, describe} from '@augment-vir/test'; * * function myFunctionToTest(a: number, b: number) { * return a + b; * } * * describe(myFunctionToTest.name, () => { * snapshotCases(myFunctionToTest, [ * { * it: 'handles negative numbers', * inputs: [ * -1, * -2, * ], * }, * { * it: 'handles 0', * inputs: [ * 0, * 0, * ], * }, * { * it: 'adds', * inputs: [ * 3, * 5, * ], * }, * ]); * }); * ``` * * @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test) */ export declare function snapshotCases<const FunctionToTest extends AnyFunction>(this: void, functionToTest: FunctionToTest, testCases: ReadonlyArray<SnapshotTestCase<NoInfer<FunctionToTest>>>): void[];