deepEqual arrays if their key changed as an object
See original GitHub issueI 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:
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))
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
deepEqual arrays when their keys changed as an object #2563
I know the arr1 and arr2 has the same items and length as arrays, but array is also object. However, the keys of...
Read more >Deep comparison of objects/arrays - javascript - Stack Overflow
If two objects all share the same basic properties, then they will all reference the same hidden classes, and JSON. stringify will work...
Read more >5 Different Ways to Deep Compare JavaScript Objects
In this article, we will discuss five different ways to determine the equality of JavaScript objects. Two types of equalities in JavaScript.
Read more >How to Compare 2 Objects in JavaScript | SamanthaMing.com
Objects are reference types so you can't use === or == to compare them. To check if 2 objects have the same key...
Read more >How to check for array equality using javascript? - Flexiple
If x and y are both objects, it returns true if and only if they reference the same object. In Javascript, arrays are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The fix is out in 5.0.1, thanks again @cagen.
@cagen Please open an issue in the main AVA repository, I think this is a major issue 😮 nice catch!