@std/assert/equals - assertEquals() fails with function properties without displaying why
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**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**
```js
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`):
```plaintext
error: AssertionError: Values are not equal.
[Diff] Actual / Expected
{
x: 1,
y: [Function: y],
}
```
Output with colored highlighting (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`
Contributor guide
Research direction
Start by running the provided @std/assert/equals reproducer with deno test and inspect the assertEquals() entry point. The issue is done when failures involving function properties clearly explain that functions cannot be compared or visually indicate the uncomparable functions, including for deeply nested objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100