General Assertions
The checks that are not tied to one type: boolean-context truthiness on the factory, and definedness on every verifier.
should().true(value)/should().false(value)
Assert how the value behaves in a boolean context. Falsy values are exactly: false, 0, '', null, undefined, and NaN — everything else is truthy.
These are terminal checks (no chaining after them) and have no not form — use the opposite verb instead. Prefer them over expect(Boolean(x)).toBe(true) when the point of the test is the truthiness itself; prefer a specific verifier (string, number) whenever the type is known — the failure messages will say something useful.
defined() — on every verifier
Every verifier — number, string, array, date, objects — exposes defined(). It passes when the examined entry is neither null nor undefined and otherwise throws The entry is not defined.. It is also the guard every other check runs implicitly; see Concepts for the interaction with not.
not.defined() is the single legal way a null/undefined entry passes a chain:
When to use what
Situation | Use |
|---|---|
The type is known | the typed verifier, not |
Only "is it there" matters |
|
A flag-like result of any type |
|
Next: the typed chapters — Numbers, Strings, Dates, Arrays, Objects.