/** * Actions must have a `type` field that indicates the type of action being * performed. * * Copy of https://github.com/reduxjs/redux/blob/32ac7e64bf548e0287807fae9e622aa9c55ff065/index.d.ts#L18 * * @template T the type of the action's `type` tag. */ export interface Action { type: T; } /** * An Action type which accepts any other properties. * * Copy of https://github.com/reduxjs/redux/blob/32ac7e64bf548e0287807fae9e622aa9c55ff065/index.d.ts#L28 */ export interface AnyAction extends Action { [extraProps: string]: any; } /** * An Async Action type which has a Function as payload. * This extends from AnyAction and thus other properties are also accepted. * * However, you can also think of this as a derivation of Flux Standard Action, */ export interface AsyncAction extends AnyAction { payload: Function; } /** * A Test Action defines actions which conforms to either an * AsyncAction or an AnyAction. */ export declare type TestAction = AsyncAction | AnyAction; /** * Action type for those functions that returns a thunk */ export declare const THUNK_ACTION = "THUNK_ACTION"; /** * ThunkArgs refers to the "getState" and "extraArguments" parameters * of a thunk. For reference, a thunk is called with the following * signature (dispatch, getState, extraArguments.) * * In the context of this project, these are used with mocks to guide the * executed thunk to a particular execution flow for testing. */ export declare type ThunkArgs = [(Function | null)?, unknown?]; /** * CallList is a lit of TestActions which are executed * during the process of executing a thunk. */ export declare type CallList = TestAction[]; /** * jest.fn().mock.calls */ export declare type JestCallList = CallList[]; /** * An action tracer that allows you to step through * the list of dispatched actions one by one. */ export interface ActionTracer { current(): TestAction | void; next(): TestAction | void; prev(): TestAction | void; } /** * The action runner takes an action and recursively * calls any thunks with an action runner. * * @param action The action to be dispatched. Can be a thunk. * @returns A promise */ export interface ActionRunner { (action: TestAction | Function): Promise; } /** * This is a minimal interface for storing the dispatched * actions and all subsequent actions that were triggered from it * in a call stack. * * Think of it as a mock equivalent. */ export interface ActionStore { /** * Returns the entire call stack. */ readonly calls: CallList; /** * Gets an action at a particular index of the call stack. * * @param index The position of the action which was called. * @returns An action or undefined if not found. */ index(index: number): TestAction | void; /** * Adds an action to it's own internal call stack. * * @param action TestAction * @returns void */ add(action: TestAction): unknown; } /** * Normalizes actions by converting thunks into an AsyncAction * * @param action An action or thunk * @returns An action object */ export declare function actionNormalizer(action: TestAction | Function): TestAction; /** * Alias for actionNormalizer */ export declare const actionNormaliser: typeof actionNormalizer; /** * Normalizes and stringifies the values using pretty-format * * @param value Any value * @returns A pretty-formatted stringified value. */ export declare function createSnapshotString(value: any): string; /** * Creates a snapshot friendly representation of an action. * * @param action An action or thunk. * @returns A pretty-formatted stringified action or thunk. */ export declare function actionSnapshot(action: TestAction | Function): string; /** * Creates a snapshot representation for all values within an array * * @param actions An array of actions. * @returns A pretty-formatted stringified list of actions. */ export declare function actionArraySnapshot(actions: (TestAction | Function)[]): string; /** * Creates a snapshot representation of entire action call stack of an [[ActionStore]] * * @param tester An ActionStore compatible instance. * @returns A pretty-formatted stringified list of actions. */ export declare function actionTesterSnapshot(tester: ActionStore): string; /** * An action runner runs an action and recursively executes all * thunks that are found within the executed action as well * and it's subsequent actions. * * @param tester An ActionStore compatible instance. * @param thunkArgs getState and extraArguments of a thunk * @returns An action runner. */ export declare function createActionRunner(tester: ActionStore, ...thunkArgs: ThunkArgs): ActionRunner; /** * Gets a tracer instance for the specified ActionStore * * @param tester An ActionStore compatible instance. * @returns An action tracer */ export declare function actionTracer(tester: ActionStore): ActionTracer; /** * Gets an array of action.types from the call stack of the specified ActionStore * * @param tester An ActionStore compaitble instance * @returns An array of action.types */ export declare function actionTypes(tester: ActionStore): string[]; /** * A test-framework independent test runner * This encapsulates the singular functions within this library into a class */ export declare class ActionTester implements ActionStore { private callList; private thunkArgs; readonly calls: CallList; add: (action: TestAction) => void; index: (index: number) => void | AnyAction | AsyncAction; /** * Sets the remaining 2 arguments of a thunk action. * * @param getState Mock store.getState function * @param extraArgument Mock values injected via thunk.withExtraArgument * @returns void */ setArgs: (getState?: Function | null | undefined, extraArgument?: unknown) => void; /** * Dispatches an action and recursively executes all thunks of an action * and it's subsequent actions. * * @param action TestAction | Function * @returns Promise */ dispatch: (action: Function | AnyAction | AsyncAction, done?: (() => void) | undefined) => Promise; /** * Gets an array of action.type of dispatched actions * * @returns An array of action.type */ toTypes: () => string[]; /** * Gets a object containing step functions to step through the calls. * * @returns An action tracer */ toTracer: () => ActionTracer; /** * Generates a snapshot of the dispatched actions. * * @returns A pretty-formatted stringified value. */ toSnapshot: () => string; } /** * An ActionTester class which is jest compatible */ export declare class JestActionTester extends ActionTester { private jestFn; /** * Takes in jest mock function. * * @param jestFn jest.fn() */ constructor(jestFn: any); /** * Re-maps all jest.fn().mock.calls array to the ActionTester * compatible version * * @returns An array of actions */ readonly calls: CallList; /** * Retrieves the action from the provided jest.fn() */ index: (index: number) => void | AnyAction | AsyncAction; /** * Calls the action with the provided jest.fn(); */ add: (action: TestAction) => void; }