UNPKG

strong-mock

Version:

Type safe mocking library for TypeScript

29 lines (28 loc) 1.1 kB
import type { Property } from '../proxy'; import type { TypeMatcher } from './matcher'; type ObjectType = Record<Property, unknown>; type NonEmptyObject<T extends ObjectType> = keyof T extends never ? never : T; type DeepPartial<T> = T extends ObjectType ? { [K in keyof T]?: DeepPartial<T[K]>; } : T; /** * Check if an object recursively contains the expected properties, * i.e. the expected object is a subset of the received object. * * @param partial A subset of the expected object that will be recursively matched. * Supports nested matchers. * Concrete values will be compared with {@link deepEquals}. * * @see {@link isPlainObject} if you want to match any plain object. * * @example * const fn = mock<(pos: { x: number, y: number }) => number>(); * when(() => fn(It.containsObject({ x: 23 }))).returns(42); * * fn({ x: 23, y: 200 }) // returns 42 * * @example * It.containsObject({ foo: It.isString() }) */ export declare const containsObject: <T, K extends DeepPartial<T>>(partial: K extends ObjectType ? NonEmptyObject<K> : never) => TypeMatcher<T>; export {};