add: unit and integration testing
This commit is contained in:
+186
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
export declare const arrayBufferEquality: (
|
||||
a: unknown,
|
||||
b: unknown,
|
||||
) => boolean | undefined;
|
||||
|
||||
/**
|
||||
* Structural type for any object honoring Jest's asymmetric matcher protocol
|
||||
* (e.g. `expect.any(...)`, `expect.objectContaining(...)`). Detected at runtime
|
||||
* by {@link equals}.
|
||||
*/
|
||||
export declare type AsymmetricMatcher = {
|
||||
asymmetricMatch(other: unknown): boolean;
|
||||
toString(): string;
|
||||
getExpectedType?(): string;
|
||||
toAsymmetricMatcher?(): string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces `T` with `T | AsymmetricMatcher`, recursing into nested objects and
|
||||
* arrays:
|
||||
* ```ts
|
||||
* type DeepAsymmetricMatcher<boolean>; // AsymmetricMatcher | boolean
|
||||
* type DeepAsymmetricMatcher<{ foo: number }>; // AsymmetricMatcher | { foo: AsymmetricMatcher | number }
|
||||
* type DeepAsymmetricMatcher<[string]>; // AsymmetricMatcher | [AsymmetricMatcher | string]
|
||||
* ```
|
||||
*/
|
||||
declare type DeepAsymmetricMatcher<T> = T extends object
|
||||
? | AsymmetricMatcher
|
||||
| {
|
||||
[K in keyof T]: DeepAsymmetricMatcher<T[K]>;
|
||||
}
|
||||
: AsymmetricMatcher | T;
|
||||
|
||||
export declare function emptyObject(obj: unknown): boolean;
|
||||
|
||||
export declare const equals: EqualsFunction;
|
||||
|
||||
export declare type EqualsFunction = (
|
||||
a: unknown,
|
||||
b: unknown,
|
||||
customTesters?: Array<Tester>,
|
||||
strictCheck?: boolean,
|
||||
) => boolean;
|
||||
|
||||
/**
|
||||
* Like the built-in `Parameters<F>` utility type, but each parameter accepts an
|
||||
* asymmetric matcher (recursively for nested objects), and overloaded functions
|
||||
* yield a union of all overload parameter tuples.
|
||||
*/
|
||||
export declare type FunctionParameters<F> =
|
||||
FunctionParametersInternal<F> extends never
|
||||
? Array<unknown>
|
||||
: FunctionParametersInternal<F>;
|
||||
|
||||
/**
|
||||
* 1. If the function is overloaded or has no parameters → overloaded form
|
||||
* (union of tuples, up to 15 overloads).
|
||||
* 2. If the function has parameters → simple form.
|
||||
* 3. else → `never`.
|
||||
*/
|
||||
declare type FunctionParametersInternal<F> = F extends {
|
||||
(...args: infer P1): any;
|
||||
(...args: infer P2): any;
|
||||
(...args: infer P3): any;
|
||||
(...args: infer P4): any;
|
||||
(...args: infer P5): any;
|
||||
(...args: infer P6): any;
|
||||
(...args: infer P7): any;
|
||||
(...args: infer P8): any;
|
||||
(...args: infer P9): any;
|
||||
(...args: infer P10): any;
|
||||
(...args: infer P11): any;
|
||||
(...args: infer P12): any;
|
||||
(...args: infer P13): any;
|
||||
(...args: infer P14): any;
|
||||
(...args: infer P15): any;
|
||||
}
|
||||
? | WithAsymmetricMatchers<P1>
|
||||
| WithAsymmetricMatchers<P2>
|
||||
| WithAsymmetricMatchers<P3>
|
||||
| WithAsymmetricMatchers<P4>
|
||||
| WithAsymmetricMatchers<P5>
|
||||
| WithAsymmetricMatchers<P6>
|
||||
| WithAsymmetricMatchers<P7>
|
||||
| WithAsymmetricMatchers<P8>
|
||||
| WithAsymmetricMatchers<P9>
|
||||
| WithAsymmetricMatchers<P10>
|
||||
| WithAsymmetricMatchers<P11>
|
||||
| WithAsymmetricMatchers<P12>
|
||||
| WithAsymmetricMatchers<P13>
|
||||
| WithAsymmetricMatchers<P14>
|
||||
| WithAsymmetricMatchers<P15>
|
||||
: F extends (...args: infer P) => any
|
||||
? WithAsymmetricMatchers<P>
|
||||
: never;
|
||||
|
||||
export declare const getObjectKeys: (object: object) => Array<string | symbol>;
|
||||
|
||||
export declare const getObjectSubset: (
|
||||
object: any,
|
||||
subset: any,
|
||||
customTesters?: Array<Tester>,
|
||||
seenReferences?: WeakMap<object, boolean>,
|
||||
) => any;
|
||||
|
||||
declare type GetPath = {
|
||||
hasEndProp?: boolean;
|
||||
endPropIsDefined?: boolean;
|
||||
lastTraversedObject: unknown;
|
||||
traversedPath: Array<string>;
|
||||
value?: unknown;
|
||||
};
|
||||
|
||||
export declare const getPath: (
|
||||
object: Record<string, any>,
|
||||
propertyPath: string | Array<string>,
|
||||
) => GetPath;
|
||||
|
||||
export declare function isA<T>(typeName: string, value: unknown): value is T;
|
||||
|
||||
export declare const isError: (value: unknown) => value is Error;
|
||||
|
||||
export declare const isOneline: (
|
||||
expected: unknown,
|
||||
received: unknown,
|
||||
) => boolean;
|
||||
|
||||
export declare const iterableEquality: (
|
||||
a: any,
|
||||
b: any,
|
||||
customTesters?: Array<Tester>,
|
||||
aStack?: Array<any>,
|
||||
bStack?: Array<any>,
|
||||
) => boolean | undefined;
|
||||
|
||||
export declare const partition: <T>(
|
||||
items: Array<T>,
|
||||
predicate: (arg: T) => boolean,
|
||||
) => [Array<T>, Array<T>];
|
||||
|
||||
export declare const pathAsArray: (propertyPath: string) => Array<any>;
|
||||
|
||||
export declare const sparseArrayEquality: (
|
||||
a: unknown,
|
||||
b: unknown,
|
||||
customTesters?: Array<Tester>,
|
||||
) => boolean | undefined;
|
||||
|
||||
export declare const subsetEquality: (
|
||||
object: unknown,
|
||||
subset: unknown,
|
||||
customTesters?: Array<Tester>,
|
||||
) => boolean | undefined;
|
||||
|
||||
export declare type Tester = (
|
||||
this: TesterContext,
|
||||
a: any,
|
||||
b: any,
|
||||
customTesters: Array<Tester>,
|
||||
) => boolean | undefined;
|
||||
|
||||
export declare interface TesterContext {
|
||||
equals: EqualsFunction;
|
||||
}
|
||||
|
||||
export declare const typeEquality: (a: any, b: any) => boolean | undefined;
|
||||
|
||||
/**
|
||||
* Maps each parameter slot of a tuple to `T | AsymmetricMatcher` (recursively
|
||||
* via {@link DeepAsymmetricMatcher}). Falls back to `never` for the
|
||||
* `Array<unknown>` "any-shape" case so that {@link FunctionParameters} can
|
||||
* collapse it back to `Array<unknown>` for `UnknownFunction`-like mocks.
|
||||
*/
|
||||
declare type WithAsymmetricMatchers<P extends Array<any>> =
|
||||
Array<unknown> extends P
|
||||
? never
|
||||
: {
|
||||
[K in keyof P]: DeepAsymmetricMatcher<P[K]>;
|
||||
};
|
||||
Reference in New Issue
Block a user