
A scoreboard offers an alternate order while keeping the original arrival stream visible in another tab. The result contains both the sorted view and the untouched input. A numeric comparator avoids lexicographic ordering of numbers.
Inspect the value before the UI formats it
The example keeps the input to Array.toSorted outside the function, so it is possible to run the same transformation in a test. The comparison uses concrete data rather than the rendered component. If the application accepts a value from JSON, run the fixture after parsing that JSON to preserve the relevant types.
function evaluate(value) {
return [value.toSorted((a,b)=>a-b),value];
}
const samples = [[12, 3, 20], [4, 4, 1], []];
for (const sample of samples) console.log(evaluate(sample));What appears for each input
| Input | Return value |
|---|---|
| [12, 3, 20] | [[3, 12, 20], [12, 3, 20]] |
| [4, 4, 1] | [[1, 4, 4], [4, 4, 1]] |
| [] | [[], []] |
For [12, 3, 20], the observed output is [[3, 12, 20], [12, 3, 20]]. With [4, 4, 1], it becomes [[1, 4, 4], [4, 4, 1]]. Compare the two as a before-and-after record. Keeping the input beside the expectation makes it possible to distinguish an intentional contract change from a change introduced by a different parser or runtime.
For [], the operation returns 2 top-level items. An assertion on that count would miss a change in their contents. Capture the expected sequence or compare membership explicitly if order has no meaning in the product.
When the integration needs another check
The copy is shallow. Mutating a shared object inside either array still changes what the other view can observe.
Run one case twice through the real feature and look at both the displayed value and its stored representation. A component may coerce a result to text even when the implementation returns an ordered collection of values. Keep a failing sample small enough that it can travel with a bug report, including the browser or Node version that produced it.
Turn the edge behaviour into a regression test
Edit a nested object in one sorted view when the elements are actual objects rather than numbers. This shows the boundary between copying an array container and deep-copying its contents, an important difference for an editable dashboard.
The same JavaScript function was also run with [] / [12] / [20, 3, 12]. These additional inputs change the boundary without changing the implementation. An exception name in the table records where the operation rejects an input; a returned empty or zero value records a successful call. Choose deliberately which of those outcomes the surrounding feature should expose.
| Additional fixture | Result or exception |
|---|---|
| [] | [[], []] |
| [12] | [[12], [12]] |
| [20, 3, 12] | [[3, 12, 20], [20, 3, 12]] |
JavaScript standard library reference · MDN JavaScript language guide
Sources and further reading
Cover photograph: Cherry MX 3850 USB - case removed-3537 by Raimond Spekking. CC BY-SA 4.0. Cropped and typeset for this cover. The photograph illustrates the topic. This image adaptation uses the same share-alike license.
