@reactables/testing
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.3 • Public • Published

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;
}
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;

/@reactables/testing/

    Package Sidebar

    Install

    npm i @reactables/testing

    Weekly Downloads

    2

    Version

    1.0.0-beta.3

    License

    ISC

    Unpacked Size

    6.61 kB

    Total Files

    11

    Last publish

    Collaborators

    • laidav