
A bulk editor marks a batch ready only if it contains at least one accepted file. Every returns true for an empty array. The explicit length check encodes the additional submission requirement.
Inspect the value before the UI formats it
The example keeps the input to Array.every 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.every(n=>n>0),value.length>0 && value.every(n=>n>0)];
}
const samples = [[1, 2], [2, 0], []];
for (const sample of samples) console.log(evaluate(sample));What appears for each input
| Input | Return value |
|---|---|
| [1, 2] | [true, true] |
| [2, 0] | [false, false] |
| [] | [true, false] |
For [1, 2], the observed output is [true, true]. With [2, 0], it becomes [false, false]. Record both observations in the test that owns the public behaviour. A later refactor can swap the mechanics underneath it as long as the callers continue to receive the values they rely on.
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
Sparse arrays skip missing elements in many iteration methods. A validated dense array is easier to reason about.
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
Put an empty batch through the same screen as a populated one. A green readiness badge can be mathematically consistent with every and still violate the user's expectation that an upload contains at least one selected file.
The same JavaScript function was also run with [] / [1] / [2, 1]. 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 |
|---|---|
| [] | [true, false] |
| [1] | [true, true] |
| [2, 1] | [true, true] |
JavaScript standard library reference · MDN JavaScript language guide
Sources and further reading
Cover photograph: Raspberry Pi 2 Model B v1.1 underside new (bg cut out) by Multicherry. 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.
