UnderscoreJS’s _.isEqual() is perfect for unit tests

19 Feb
UPDATE: @andybeeching points out what shouldabeen the bleeding obvious: QUnit’s same(). (I’d internalised QUnit as having just ok() and equal() as I always think it’s unusally small compared to Junit’s myriad ofassertGreaterThan etc (which I prefer)…I forgot the third and obvious one.)

Drop this into your QUnit (http://docs.jquery.com/QUnit) test (or similar in other Javascript testing frameworks). It’s a drop-in replacement for the standard “equals” equality test in QUnit. It will recurse through data structures and so check proper equality of objects and arrays. Plus, it will still compare normal values too, using === (http://longgoldenears.blogspot.com/2007/09/triple-equals-in-javascript.html).

I just started using it here:

to test:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: