Unit Testing arrays with QUnit

April 4, 2014

alt text

How to test Array equality

When testing arrays with QUnit you may wish to assert that one array is equal to another array.

Qunit provides the equal( actual, expected, message ) method for asserting that actual value is equal to the expected value.

so what happens in the following test scenario

this…

It fails horribly onscreen with an error from the sourceStackTrace() output from within QUnit.push

So how can we test arrays with QUnit?

We can use the deepEqual() assert method.

Qunit provides the deepEqual( actual, expected, message ) method for a deep recursive comparison, working on primitive types, arrays, objects, regular expressions, dates and functions.

So let’s test with deepEqual instead

It passes

due to the implementation of the deepEqual() method there is a call innerEquiv which recursively compares each item within the array