Documentation
    Preparing search index...
    • 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 undefined are 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.

      Type Parameters

      • X

        The first value to compare

      • Y = X

      Parameters

      • title: string

        Descriptive title used in error messages when values differ

      • X: X
      • y: Y | null | undefined

        The second value to compare (can be null or undefined)

      • Optionalexception: (key: string) => boolean

        Optional filter function to exclude specific keys from comparison

      Returns void

      // 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);

      Error with detailed diff information when values are not equal

      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.

      contracts/common.md#prohibited-implementation-shortcuts The exception filter is the caller's; the function contains no key name of its own.

      contracts/common.md#meaningful-documentation The comment states the JSON form, the key-walking rule with its consequence for extra keys, the array length rule, and the exception filter, with examples.