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