The first value to compare
// Basic equality
TestValidator.equals(
"response should match expected",
expectedUser,
actualUser,
);
// Ignore timestamps in comparison
TestValidator.equals(
"user data should match",
expectedUser,
actualUser,
(key) => key === "updatedAt",
);
// Validate API response structure
TestValidator.equals(
"API response structure",
{ id: 1, name: "John" },
{ id: 1, name: "John" },
);
// Type-safe nullable comparisons
const nullableData: { name: string } | null = getData();
TestValidator.equals("nullable check", nullableData, null);
contracts/common.md#principled-implementation Both values are compared through json_equal_to, which walks the keys of the first value, so the second value may carry extra keys and the typing Y extends X states that; the differing accessors are listed in the error with both values serialized.
contracts/common.md#clear-and-simple-design A thin wrapper over the shared comparison that adds the message.
Validates deep equality between two values using JSON comparison.
Performs recursive comparison of objects and arrays through their JSON form. The comparison walks the keys of the first value, so a key that only the second value has is ignored, which is why the second value may be a subtype of the first. Keys whose value in the first value is
undefinedare skipped, and arrays must have the same length. Supports an optional exception filter to ignore specific keys during comparison. Useful for validating API responses, data transformations, and object state changes.Processing cost: The shared JSON walker traverses the first value and its corresponding second-value positions once, with recursion and accessor output proportional to visited structure; serialization occurs only on failure.