deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

`assertEquals` throws when comparing unique symbols without showing the difference

Open jespertheend opened this issue 1 year ago • 2 comments

Describe the bug

When two objects contain two unique symbols, assertEquals throws without any meaningful explanation.

Steps to Reproduce

import {assertEquals} from "https://deno.land/[email protected]/testing/asserts.ts";
assertEquals(Symbol(), Symbol());

results in the following error:

[Diff] Actual / Expected

Symbol()

Expected behavior

Whether the function should throw is up for debate I think. But the current error message is rather unclear. This is just a simple example comparing two symbols, but the way I found out about this was because I was comparing two large structures where only a single symbol property was different.

Environment

  • OS: 22.10
  • deno version: 1.32.1
  • std version: 0.186.0

jespertheend avatar May 07 '23 13:05 jespertheend

Just out of curiosity, what should the diff show in your example?

denizdogan avatar May 07 '23 13:05 denizdogan

In the example above, I think just making the Symbol() red should be enough. In case of more complex cases ideally it would highlight the unique symbols that are different while keeping the rest gray as it currently is.

Not sure how feasible this is though, maybe just including the name of the property that has a mismatch in the error message would already be a lot more helpful. For instance

const obj = {
	path: {
		to: {
			object: {
				[Symbol()]: "value"
			}
		}
	}
}

could show the message

Values at "path.to.object" are not reference-equal.

jespertheend avatar May 07 '23 13:05 jespertheend