I’m creating test in cypress using typescript, I’m not sure how to assert that all options in drop down are unique - I found bug where is situation that values are duplicated multiple times - it’s a drop down with search results. I’m not sure how check that each value in this drop down is unique. Can you help me or direct how to do it in the easiest and best way?
1 Answer
Get the text and add to a array
Convert array to set and compare the size
Set will have only unique elements (Removes the duplicates)
So if length of set and array are different , it means there where duplicate entries in the array.
var arr = [55, 44, 65, 55];
var set = new Set(arr);
console.log(set.size === arr.length);
set.forEach(x => {console.log(x)});
-
Can you explain to op why comparing a set to array will do the job?– MoroCommented Sep 9, 2020 at 8:05
-
1
-