
A build matrix can stop at the first platform marked unsupported and highlight its row in a review table. A result of zero is a valid first position; minus one marks absence. Testing the result for truthiness swaps those meanings.
A runnable JavaScript fixture
The example keeps the input to Array.findIndex 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.findIndex(x=>x===false);
}
const samples = [[true, false, false], [false], [true, true]];
for (const sample of samples) console.log(evaluate(sample));The result for three concrete cases
| Input | Return value |
|---|---|
| [true, false, false] | 1 |
| [false] | 0 |
| [true, true] | -1 |
For [true, false, false], the observed output is 1. With [false], it becomes 0. The useful comparison is at the application boundary. Run the pair against the input as it reaches the program after decoding or parsing, then inspect what the next component receives.
The value for [true, true] is -1. Record the unit or indexing convention next to that expectation. A second implementation can return the same type and still disagree about where a boundary falls or which observations enter the calculation.
An acceptance check for the real feature
Retain the matching row's identifier if a live list can be reordered before the UI uses its index.
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 a numeric measurement. Keep a failing sample small enough that it can travel with a bug report, including the browser or Node version that produced it.
One more fixture before integrating
Test a first-position match, a later-position match and no match. A branch written as if(index) handles the latter two in surprising ways, which is why the explicit index comparison belongs in the acceptance test.
The same JavaScript function was also run with [] / [true] / [false, false, true]. 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 |
|---|---|
| [] | -1 |
| [true] | -1 |
| [false, false, true] | 0 |
JavaScript standard library reference · MDN JavaScript language guide
Sources and further reading
Cover photograph: 2018 Bay Area Mechanical Keyboard Meetup (31007926627) by Patrick Breen. CC BY 2.0. Cropped and typeset for this cover. The photograph illustrates the topic.
