Methods
The verifier for functions: should().method(fn) checks that invoking the function throws — or that it completes and hands the produced value back for further chains.
should().method(fn).throws(...)
throws(...args) invokes the function with the given arguments and passes when the call throws any exception. not.throws() is the readable replacement for a hand-rolled "called and nothing exploded" try/catch.
returns(...args) — run and keep the value
returns(...args) invokes the function, asserts that it completes without throwing, and returns the produced value — the bridge from a method check back to the typed verifiers:
Under not, returns() asserts the opposite — the invocation must throw — and yields undefined.
Definedness
Like every verifier, should().method(null).throws() throws The entry is not defined. regardless of not; use defined()/not.defined() when the function itself may be absent — a not-yet-assigned callback, an optional dependency.
When to use what
Situation | Use |
|---|---|
The call must fail |
|
The call must succeed and the value matters |
|
The call must succeed and the value does not matter |
|