deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

assertEquals' diff: does not account for extra properties on arrays

Open mfulton26 opened this issue 3 years ago • 3 comments

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.

mfulton26 avatar Jul 10 '21 14:07 mfulton26

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
Deno.inspect(Object.assign([1], {"-1":-1, hello:"world"}), {compact:false})
[
  1
]
NodeJS
const util = require("util")
util.inspect(Object.assign([1], {"-1":-1, hello:"world"}), {compact:false})
[
  1,
  '-1': -1
]

lowlighter avatar Jul 21 '21 17:07 lowlighter

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.

mfulton26 avatar Jul 21 '21 23:07 mfulton26

custom props on typed arrays also not listed in Deno.inspect

exe-dealer avatar Jan 14 '22 07:01 exe-dealer

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.

iuioiua avatar Nov 29 '23 07:11 iuioiua