callbag-mock
Callbag mock with manual emitting and signal tapping.
Useful for unit testing other callbag packages, or for triggering signals in callbag chains from non-callbag code.
npm install callbag-mock
usage
mock
The isSource
boolean decides whether the mock will handshake back when initialised (meaning it is a source).
A reporter
, if provided, will be called each time the mock receives a signal:
void
The third in
parameter tells you whether the signal was received in the function body or the talkback.
The mock instance has an .emit(t,d)
method for manually triggering signals:
There is a .getReceivedData()
method to get all received data so far.
Use .getMessages()
if you want all messages as [t, d]
tuples.
Get references to sent talkbacks through .getTalkback()
and received talkbacks through .getPartnerTalkback()
.
You can also .checkConnection()
to see whether or not the callbag has a live connection.
example
const mock = ; const reporter = { if t !== 0 console;} const source = ;const sink = ; source; // falsesink; // false ; source === sink // truesink === source // true source; // 'sink', 'body', 1, 'foo'sink; // 'source', 'talkback', 1, 'bar' sink; // ['foo'] source; // truesink; // true