@reactables/testing
v1.0.0-beta.3
Published
Helpers for testing reactables
Downloads
5
Readme
Reactables Testing
Description
Testing helpers for reactables
Table of Contents
Installation
npm i -D @reactables/testing
API
testFlow
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;
FlowTest
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) |
Flow
Used to simulate a user flow. An array of functions used to envoke a reactable's action methods.
type Flow = (() => void)[];
FlowFactory
Factory function for creating a Flow
from a reactable's action methods.
type FlowFactory<T> = (actions: T) => Flow;