Test Generator Runner
testGeneratorRunner package provides a set of tools to create both unit and integration tests for routines. It is widely used internally for testing purposes.
integrationTestRunner
Integration test runner will record all calls inside our routines and provide a way to assert whether the particular call happened during the test run.
It also provides a way to advance a routine's internal generator to control it execution and test against its different states.
unitTestGeneratorRunner
Accepts an iterator as well much like a function above but will return an object that exposes a single .next
method with the same signature. unitTestGeneratorRunner
will iterate through a supplied iterator a little bit differently, see a paragraph below for a detailed explanation.
How these test runners step through an iterator
When calling a .next
method or any of its aliases like .runNTimes
or .runTillEnd
, test generator runner will peform iterator.next
on a supplied iterator. When processing this call, if any generators, promises, cancellablePromises or operators are encountered, they will be executed during a current step from start to end in integrationTestGeneratorRunner
. unitTestGeneratorRunner
will not execute nested generators, routines and operators right away and each next successive call will iterate through that nested generator, operator or routine until its done or throws an error. When it is done, the next .next
will continue iterating through a parent iterator. unitTestGeneratorRunner
allows you to precisely iterate through each and every step of the generator that is being tested and all of its children recursively.
API
integrationTestGeneratorRunner<G extends Generator<unknown, any, unknown>>(iterator: G): IntegrationGeneratorTestRunner
Will accept an iterator and produce an IntegrationGeneratorTestRunner
object.
IntegrationGeneratorTestRunner
next: (arg?: any) => Promise<StepResult>
Will cal a .next
method on an internal iterator with a provided argument and return a result with done
and value
properties.
runNTimes(times: number): Promise<StepResult>
Simply a shorthand for calling .next
N times.
runTillEnd(): Promise<StepResult>
A shorthand to run iterator till its done.
StepResult
value: any
Is a value yielded from a supplied iterator as a result of .next
call
done: boolean
Indicates whether a supplied iterator is done being iterated through
Last updated