Hi,
I have a usecase where I need to validate whether the response has all records sorted by a column and in the respective sorting order. I have used ‘lodash’ for this. I have used ‘orderBy’ function of lodash to get the expected sorting and compared it against the actual response by using ‘eql’. The following is sample code that I have written
The above code works. My response has an array of records. The expected sort order has records as in response but in shuffled order. More than half of the records are shuffled in the Expected sort order. Due to this when I compare the expected v/s actual response, my test fails though the sorting order is Ascending in both cases. My response has a key ‘branchName’ using which the reponse is sorted and the value of ‘branchName’ for most of the elements of the records array starts with “TEST” and hence the shuffling is happening I guess. The following is my response body
Is there a way to get the expected sort order without shuffling or how do I resolve this? Can anyone please suggest?