concordancejs / concordance

Compare, format, diff and serialize any JavaScript value

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deepEqual arrays if their key changed as an object

cagen opened this issue · comments

commented

I recently write some test using AVA, something I have encountered like this below:

test('Array', t => {
  const arr1 = [1,2,3]
  const arr2 = arr1.slice()
  // normally we don't use array like this
  // but sometimes we might reach out of the array boundary unexpectedly
  for (let i = -1; i > -10; i--) {
    arr2[i] = 111
  }
  console.log(arr1, arr2)
  t.deepEqual(arr1, arr2)
})

The result is:
image

I know the arr1 and arr2 has the same items and length as arrays, but array is also object. However, the keys of object changed unexpectedly might indicate that I have write something wrong. In that case, I got passed test and know nothing about it.

How I can compare two array also as an object? I can only figure out a workaround using two assertions like this (only deal with limited situations):

t.deepEqual(arr1, arr2)
t.deepEqual(Object.keys(arr1), Object.keys(arr2))

I must have overlooked this issue. It's better filed with the AVA project instead. However Concordance should recognize the difference, so I'd love to see a reproduction if this is still a problem.

commented

I must have overlooked this issue. It's better filed with the AVA project instead. However Concordance should recognize the difference, so I'd love to see a reproduction if this is still a problem.

@novemberborn Sorry, I failed to notice this issue had been updated.
This is still a problem when I use ava@3.11.1.
Here is the example project. Running npm test will get same result.

@cagen Please open an issue in the main AVA repository, I think this is a major issue 😮 nice catch!

Turns out negative-integer properties on lists were never treated as list items (makes sense), but were not detected as properties either.

I don't know why I didn't recognize this as a Concordance bug two years ago 😄

The fix is out in 5.0.1, thanks again @cagen.