What is the easiest way to compare two arrays in QUnit

I am writing JavaScript block tests (with the QUnit library). I need to verify that my array contains the expected (and only) elements.

var array = getArrayFunction(a, b); equal(["one", "two", "three"], array, "Test is failing even if 'array' contains needed elements"); 

What would be the easiest way to do this?

+5
source share
1 answer

You should use deepEqual() instead of equal() . This will compare the array elements and the properties of the object, and not just use the comparison operator == , which evaluates to false for objects that do not have the same constructor.

Docs here: https://api.qunitjs.com/deepEqual/

Additional information on comparing JavaScript equality: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness

+5
source

Source: https://habr.com/ru/post/1232332/


All Articles