Skip to content

@std/assert/equals - assertEquals() fails with function properties without displaying why #6878

@gohjy

Description

@gohjy

Describe the bug
@std/assert/equals - assertEquals() always throws when any property or sub-property of its input objects is a function, even if they are otherwise identical. The error message contains no hints or highlighting of the functions at all, making it fairly confusing to figure out what went wrong, especially if the inputs have deeply nested objects.

Steps to Reproduce

import { assertEquals } from "jsr:@std/assert";
Deno.test("Example test", () => assertEquals(
    { x: 1, y: () => console.log(2) },
    { x: 1, y: () => console.log(2) }
));

Output (deno test):

error: AssertionError: Values are not equal.


    [Diff] Actual / Expected


    {
      x: 1,
      y: [Function: y],
    }
Output with colored highlighting (image): Image

Expected behavior

Either (or both) of:

  • The error message indicates that functions cannot be compared
  • Function is highlighted in output with an indicator that it can't be compared

Alternatively, an assertEqualsWithoutFunctions() function treating all functions as equal would be welcome too.

Environment

  • OS: Windows 11 using WSL (Ubuntu 24.04 LTS)
  • deno version: 2.5.6
  • std version: @std/assert@1.0.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions