method

test.AsymmetricMatchers.toSatisfy

predicate: (value: any) => unknown,
message?: string
): any;

Matches any received value for which predicate returns a truthy value. Use it inside toEqual or toBeCalledWith instead of a literal value.

message describes the predicate. It has no effect on the match. It is printed after the predicate wherever the matcher is printed, such as in a failure message or a snapshot.

const isOdd = (n: number) => n % 2 === 1;
expect({ count: 3 }).toEqual({ count: expect.toSatisfy(isOdd) });
expect({ count: 3 }).toEqual({ count: expect.toSatisfy(isOdd, "an odd number") });