cyclejs-mock
Utility for testing applications based on Cycle.js framework.
Short API documentation
Module cyclejs-mock
returns just one functions in which you can wrap your test
definition and get access to some useful utils. They are heavily based on
Rx.Testing module,
so its documentation may be worth to read too.
; ; { return Observable ); }
createObservable(...args)
Creates a hot observable using the specified timestamped notification messages.
It accepts any number of values created by onNext
, onError
and onCompleted
functions;
let a$ = ;
Code above creates observable that emits value 1
at time 100, value 2
at time 200
and completes at time 500.
onNext(ticks, value)
It's just Rx.ReactiveTest.onNext
method.
It accepts number of VirtualTime
ticks after that a value will be emitted and value itself.
onCompleted(ticks)
It's just Rx.ReactiveTest.onCompleted
method.
It accepts number of VirtualTime
ticks after that a completed signal will be emitted.
onError(ticks, exception|predicate)
It's just Rx.ReactiveTest.onError
method.
It accepts number of VirtualTime
ticks after that an exception will be emitted and exception itself.
If you pass function as a second argument, it will be used by custom assertion function.
; ; chai; let a$ = ; assert );
getMessages(observable)
Starts the observable and returns collection of emitted values and signals.
It uses Rx.TestScheduler.startWithTiming
method with following time values: 1, 10, 100000 (so you can assume that it starts
on the beginning of the world and lives forever).
const isEqual = RxinternalsisEqual; const err = 'bum!'; let a$ = ; let messages = ; ; ; ;
getValues(observable)
It's similar to getMessages
, but returns array of values emitted by observable.
const err = 'bum!'; let a$ = ; let values = ; assert; assert; // null for onError and onCompleted assert;
render(vdom)
Turns out VirtualDOM to real one.
let vdom =
You can use it to render your VirtualDOM stream with help of getValues
.
let vdom$ =
callWithObservables(fn, argsDefinitionObj)
Calls function with observables defined in passed object. You can provide observable or just a value that should be emitted. If function has parameter with name that can't be found in definition object, empty observable is created.
{ return RxObservable ); } let sum$ = ; assert;
mockInteractions(definitionObj)
Creates mock of interactions object based on provided definition. You can define
interaction with element using key objects in format selector@event
, ex.
.button@click
. Pass observable to use exact value in mock or just any value to
create observable emitting it. If not defined interaction is requested, empty
observable is created.
let interactions = ; let clicksOnButton$ = interactions; let inputsOnField$ = interactions; let keyupsOnBody$ = interactions; assert; assert; assert;