Validates deep equality between two values using JSON comparison.
Performs recursive comparison of objects and arrays. Supports an optional
exception filter to ignore specific keys during comparison. Useful for
validating API responses, data transformations, and object state changes.
Type Safety Notes:
The generic type T is inferred from the actual parameter (first in the
currying chain)
The expected parameter must be assignable to T | null | undefined
For objects, expected must have the same or subset of properties as
actual
For union types like string | null, ensure proper type compatibility:
constx: string | null; TestValidator.equals("works")(x)(null); // ✅ Works: null is assignable to string | null TestValidator.equals("error")(null)(x); // ❌ Error: x might be string, but expected is null
Example
// Basic equality TestValidator.equals("response should match expected")(expectedUser)(actualUser);
// Ignore timestamps in comparison TestValidator.equals("user data should match", (key) =>key === "updatedAt")( expectedUser )(actualUser);
Validates deep equality between two values using JSON comparison.
Performs recursive comparison of objects and arrays. Supports an optional exception filter to ignore specific keys during comparison. Useful for validating API responses, data transformations, and object state changes.
Type Safety Notes:
The generic type T is inferred from the
actual
parameter (first in the currying chain)The
expected
parameter must be assignable toT | null | undefined
For objects,
expected
must have the same or subset of properties asactual
For union types like
string | null
, ensure proper type compatibility:Example
Throws
Error with detailed diff information when values are not equal