Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepEqual arrays if their key changed as an object #39

Closed
cagen opened this issue Sep 21, 2017 · 5 comments · Fixed by #64
Closed

deepEqual arrays if their key changed as an object #39

cagen opened this issue Sep 21, 2017 · 5 comments · Fixed by #64

Comments

@cagen
Copy link

cagen commented Sep 21, 2017

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))
@novemberborn
Copy link
Member

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.

@cagen
Copy link
Author

cagen commented Aug 20, 2020

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.

@papb
Copy link
Contributor

papb commented Aug 20, 2020

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

@novemberborn
Copy link
Member

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 😄

@novemberborn
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants