Testing helpers for reactables
npm i -D @reactables/testing
Function for running a FlowTest
on a reactable.
// T = reactable state
// S = reactable actions
// U = reactable dependencies
// V = expected result
type testFlow = <T, S, U extends unknown[], V = T>(
flowTest: FlowTest<T, S, U, V>,
) => void;
Configuration for testing a Flow
on a reactable.
// T = reactable state
// S = reactable actions
// U = reactable dependencies
// V = expected result
export interface FlowTest<T, S, U extends unknown[] = undefined, V = T> {
description: string;
factories: {
flow: FlowFactory<S>;
reactable: (...deps: U) => Reactable<T, S>;
dependencies?: () => U;
};
expectedResult: V;
operator?: OperatorFunction<T, V | T>;
assertFunc?: (actual, expected) => void | boolean;
}
Property | Description |
---|---|
description | Describes the test. |
factories.flow |
FlowFactory that will create the flow to be tested. |
factories.reactable | Factory method creating the reactable. |
factories.dependencies | Factory function creating the reactable's dependencies. |
expectedResult | Expected result for the test. |
operator (optional) | Operator function for manipulating the final value emitted by the reactable's state observable. |
assertFunc (optional) | Function that will assert actual vs expected. (default isEqual ) |
actionInterval (optional) | Time interval between action calls in the flow run. (default 5000ms) |
Used to simulate a user flow. An array of functions used to envoke a reactable's action methods.
type Flow = (() => void)[];
Factory function for creating a Flow
from a reactable's action methods.
type FlowFactory<T> = (actions: T) => Flow;