Array Ordering
ordered() is the check the library was born from: assert that a collection came back sorted — without copying it, sorting a fixture, or comparing only two records.
On failure the chain throws Elements aren't ordered.
Settings
ordered(settings?) takes an optional ArrayOrderedSettings<T>:
Field | Type | Default | Meaning |
|---|---|---|---|
|
|
| extracts the comparable value from each element |
|
|
| expected direction |
With no settings the check compares elements as-is, ascending:
Ordering by a field
Comparison semantics
Adjacency rules, applied to the by values of neighboring elements:
equal neighbors are fine in both directions (
1, 1, 2is ascending);dir: 'asc'requires each value to be<=the next;descrequires>=;values are compared with JavaScript's
>/<operators — numbers and strings work naturally, mixed or non-comparable values behave as those operators do.
Negation
Note that not.ordered() asserts some disorder, not a specific inverse ordering — if the point of the test is a concrete order, assert ordered({ dir: 'desc' }) positively instead.
Signatures
See API reference — Array verifier and the ArrayOrderedSettings fields in the API reference.