Why does the following fail?
expect([0,0]).to.equal([0,0]);
and what is the right way to test that?
For expect, .equal
will compare objects rather than their data, and in your case it is two different arrays.
Use .eql
in order to deeply compare values. Check out this link.
Or you could use .deep.equal
in order to simulate same as .eql
.
Or in your case you might want to check .members
.
For asserts you can use .deepEqual
, link.
Try to use deep Equal. It will compare nested arrays as well as nested Json.
expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
Please refer to main documentation site.
for unordered deep equality, use members
expect([1,2,3]).to.have.members([3,2,1]); // passes expect([1,2,3]).to.have.members([1,2,3]); // passes expect([1,2,3]).to.eql([3,2,1]); // fails
source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With