17
votes

I need to assert equality between two points in my JavaScript unit tests:

var pnt1 = {x: 2, y: 3};

and

var pnt2 = {x: 2, y: 3};

When I do

assert.equal(pnt1, pnt2);

It says the points are different. Can I exclude from the check the fact that the objects are different instances (so in fact they are "not equal")?

I'd like to avoid creating a list of assert, one for each field to test (in this case .x and .y)

1

1 Answers

20
votes

Instead of .equal, use .deepEqual:

assert.deepEqual(pnt1, pnt2);

This will perform a deep comparison instead of simply checking for equality.