deno_std
deno_std copied to clipboard
assertEquals' diff: does not account for extra properties on arrays
Description
The diff printed whenever assertEquals
fails does not include non-index values (e.g. negatives numbers or arbitrary strings).
Steps to reproduce
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
Deno.test("example", () => {
const actual = [1, 2, 3];
actual[-1] = 0;
actual[Infinity] = 9;
const expected = [1, 2, 3];
expected[-1] = 0;
expected[Infinity] = 42;
assertEquals(actual, expected);
});
Actual behavior
failures:
example
AssertionError: Values are not equal:
[Diff] Actual / Expected
[
1,
2,
3,
]
Expected behavior
Some representation of non-index entries on the array.
Potential diff of array with non-index entries
Adopts syntax similar to that for empty array items (e.g. <12 empty items>
).
failures:
example
AssertionError: Values are not equal:
[Diff] Actual / Expected
[
<"-1": 0>,
1,
2,
3,
- <Infinity: 9>,
+ <Infinity: 42>,
]
Desktop
- OS: macOS Big Sur
- Version 11.4
deno 1.11.5 (release, x86_64-apple-darwin)
v8 9.1.269.35
typescript 4.3.2
Additional context
This may be functionality that can be pushed into Deno.inspect
as this could be helpful even in non-testing situations but in this case it causes some test(s) to fail with a diff that doesn't explain what is wrong which is not ideal. Thank you.
I think this is an upstream issue.
Deno.inspect
(which is used for testing functions internally) have a different behaviours than in NodeJS.
It isn't able to list extra properties from arrays:
Deno |
|
|
NodeJS |
|
|
Yeah, that makes sense. I was wondering if we would need to open an issue for Deno.inspect
itself and that sounds like the case.
custom props on typed arrays also not listed in Deno.inspect
The snippet provided now prints the following:
error: AssertionError: Values are not equal.
[Diff] Actual / Expected
[
1,
2,
3,
"-1": 0,
- Infinity: 9,
+ Infinity: 42,
]
Closing as this issue appears to have now been fixed. Thank you for reporting, @mfulton26.