UNPKG

tstyche

Version:

Everything You Need for Type Testing.

217 lines (212 loc) 5.98 kB
interface Describe { /** * Defines a group of tests. * * @param name - The name of the group. * @param callback - The function to create a scope for a group of tests. */ (name: string, callback: () => void | Promise<void>): void; /** * Marks a group of tests as focused. * * @param name - The name of the group. * @param callback - The function to create a scope for a group of tests. */ only: (name: string, callback: () => void | Promise<void>) => void; /** * Marks a group of tests as skipped. * * @param name - The name of the group. * @param callback - The function to create a scope for a group of tests. */ skip: (name: string, callback: () => void | Promise<void>) => void; /** * Marks a group of tests as yet to be implemented. * * @param name - The name of the group. * @param callback - The function to create a scope for a group of tests. */ todo: (name: string, callback?: () => void | Promise<void>) => void; } interface Matchers { /** * Checks if the type is the same as the given type. */ toBe: { /** * Checks if the type is the same as the given type. */ <T>(): void; /** * Checks if the type is the same as type of the given expression. */ (target: unknown): void; }; /** * Checks if the type is assignable from the given type. */ toBeAssignableFrom: { /** * Checks if the type is assignable from the given type. */ <T>(): void; /** * Checks if the type is assignable from type of the given expression. */ (target: unknown): void; }; /** * Checks if the type is assignable to the given type. */ toBeAssignableTo: { /** * Checks if the type is assignable to the given type. */ <T>(): void; /** * Checks if the type is assignable to type of the given expression. */ (target: unknown): void; }; } interface Matchers { /** * Checks if the JSX component accepts the given props. */ toAcceptProps: (props: Record<string, unknown>) => void; /** * Checks if the decorator is applicable to the given class or class member. */ toBeApplicable: (target: unknown, context: DecoratorContext) => void; /** * Checks if the function is callable with the given arguments. */ toBeCallableWith: (...args: Array<unknown>) => void; /** * Checks if the class is constructable with the given arguments. */ toBeConstructableWith: (...args: Array<unknown>) => void; /** * Checks if the generic is instantiable with the given type arguments. */ toBeInstantiableWith: <T extends [...args: Array<unknown>]>() => void; /** * Checks if the type has the given property. */ toHaveProperty: (key: string | number | symbol) => void; } interface Matchers { /** * Checks if the type raises an error. * * @deprecated This API is planned to be removed. For a replacement, see https://tstyche.org/guides/expect-errors. */ toRaiseError: (...target: Array<string | number | RegExp>) => void; } interface Modifier { /** * Indicates a type-level assertion. */ type: Matchers & { /** * Negates the assertion. */ not: Matchers; }; } interface Expect { /** * Builds an assertion. */ <S>(): Modifier; /** * Builds an assertion. */ (source: unknown): Modifier; /** * Marks an assertion as focused. */ only: { /** * Marks an assertion as focused. */ <S>(): Modifier; /** * Marks an assertion as focused. */ (source: unknown): Modifier; }; /** * Marks an assertion as skipped. */ skip: { /** * Marks an assertion as skipped. */ <S>(): Modifier; /** * Marks an assertion as skipped. */ (source: unknown): Modifier; }; } interface Test { /** * Defines a single test. * * @param name - The name of the test. * @param callback - The function with a code snippet and assertions. */ (name: string, callback: () => void | Promise<void>): void; /** * Marks a test as focused. * * @param name - The name of the test. * @param callback - The function with a code snippet and assertions. */ only: (name: string, callback: () => void | Promise<void>) => void; /** * Marks a test as skipped. * * @param name - The name of the test. * @param callback - The function with a code snippet and assertions. */ skip: (name: string, callback: () => void | Promise<void>) => void; /** * Marks a test as yet to be implemented. * * @param name - The name of the test. * @param callback - The function with a code snippet and assertions. */ todo: (name: string, callback?: () => void | Promise<void>) => void; } /** * The fill-in type. Useful to fill in the required type arguments of generic types. */ type _ = never; /** * Builds an assertion. */ declare const expect: Expect; /** * Reshapes type of the given object by removing the specified keys. */ declare function omit<T, K extends PropertyKey>(object: T, ...keys: [K, ...Array<K>]): Omit<T, K>; /** * Reshapes type of the given object by keeping only the specified keys. */ declare function pick<T, K extends keyof T>(object: T, ...keys: [K, ...Array<K>]): Pick<T, K>; /** * Defines a test group. */ declare const describe: Describe; /** * Defines a single test. */ declare const it: Test; /** * Defines a single test. */ declare const test: Test; export { describe, expect, it, omit, pick, test }; export type { _ };