when sorted by
- <array-like> [when] sorted by <function> <assertion?>
Sort the subject array by a compare function that defines the sort order then delegate the return value to another assertion.
expect([2, 1, 3],'when sorted by',function (a, b) {return a - b;},'to equal',[1, 2, 3]);
In case of a failing expectation you get the following output:
expect([2, 1, 3],'when sorted by',function (a, b) {return a - b;},'to equal',[3, 2, 1]);
expected [ 2, 1, 3 ]when sorted by function (a, b) { return a - b; } to equal [ 3, 2, 1 ][┌───▷│ ┌─▷│ ││ └──└────1,2, // should be moved3 // should be moved]