General Assertions
The checks that are not tied to one type: boolean-context truthiness, exact absence (undefined/null) 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.
should().undefined(value)/should().null(value)
Assert the exact kind of absence. Both compare strictly: undefined() passes only for undefined, null() only for null — neither accepts the other.
Like true()/false() these are terminal checks with no not form. When both null and undefined count as "absent", prefer not.defined() on a verifier (below) — it covers both at once.
defined() — on every verifier
Every verifier — number, string, array, date, objects, method — 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 |
|
The exact absence kind matters ( |
|
A flag-like result of any type |
|
Next: the typed chapters — Numbers, Strings, Dates, Arrays, Objects, Methods.