If you need to compare if the before / after arrays are indeed different, do something like this:
function arraysAreEqual(before, after){
if(before.length !== after.length){
return false;
}
for(var i = 0; i < before.length; i++){
if(before[i] !== after[i]){
return false;
}
}
return true;
}
Depending on the contents of the arrays, you may need to modify the equality check in the for
loop to account for nested arrays / objects.
Assuming:
var myArray = [
{text: 'foo', value: 1},
{text: 'bar', value: 2}
]
You can use this, for example:
if(before[i].text !== after[i].text ||
before[i].value !== after[i].value){
return false;
}
With this function, you should be able to use:
expect(arraysAreEqual(array, array_after)).toBe(false);
However, the test case will fail in the (improbable, but possible) case the randomizer returns the same array as the input.