1.0.0-beta.3 • Published 1 year ago

@reactables/testing v1.0.0-beta.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Reactables Testing

Description

Testing helpers for reactables

Table of Contents

  1. Installation
  2. API
    1. testFlow
    2. FlowTest
    3. Flow
    4. FlowFactory

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;
}
PropertyDescription
descriptionDescribes the test.
factories.flowFlowFactory that will create the flow to be tested.
factories.reactableFactory method creating the reactable.
factories.dependenciesFactory function creating the reactable's dependencies.
expectedResultExpected 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;
1.0.0-beta.3

1 year ago