@simplux/testing
Version:
The testing package for simplux. Contains various testing utilities (e.g. for mocking module states and mutations).
89 lines (81 loc) • 3.39 kB
TypeScript
import { FunctionSignature } from '@simplux/core';
import { SimpluxEffect } from '@simplux/core';
import type { SimpluxModuleMarker } from '@simplux/core';
import type { SimpluxMutationMarker } from '@simplux/core';
import type { SimpluxSelectorMarker } from '@simplux/core';
/**
* Clear all mocks on any simplux functionality.
*
* @public
*/
export declare function clearAllSimpluxMocks(): void;
/**
* Specify a mock function that should be called instead of the
* effect. The effect will stay mocked indefinitely until either
* the clear callback or `clearAllSimpluxMocks` is called.
*
* @param effect - the effect to mock
* @param mockFn - the mock function to use
*
* @returns a function that clears the mock when called
*
* @public
*/
export declare function mockEffect<TEffect extends SimpluxEffect<(...args: any[]) => any>, TMock extends FunctionSignature<TEffect>>(effectToMock: TEffect, mockFn: TMock): [TMock, () => void];
/**
* Set a value that should be returned whenever the module's state
* is accessed. This mocked state value does not affect the Redux
* store and does not cause any state change susbcribers to be called
* (the only exception being that new susbcribers that are created
* while the mock state value is active will be called once with the
* mocked state value immediately after subscribing).
*
* The mocked state value will stay active indefinitely until either
* the clear callback or `clearAllSimpluxMocks` is called.
*
* @param simpluxModule - the module to mock the state for
* @param mockStateValue - the mock state value to return when the
* module's state is accessed
*
* @returns a function that clears the mock state when called
*
* @public
*/
export declare function mockModuleState<TState>(simpluxModule: SimpluxModuleMarker<TState>, mockStateValue: TState): () => void;
/**
* Specify a mock function that should be called instead of the
* mutation. The mutation will stay mocked indefinitely until either
* the clear callback or `clearAllSimpluxMocks` is called.
*
* @param mutation - the mutation to mock
* @param mockFn - the mock function to use
*
* @returns a function that clears the mock when called
*
* @public
*/
export declare function mockMutation<TState, TArgs extends any[], TMock extends (...args: TArgs) => TState>(mutation: SimpluxMutationMarker<TState, TArgs>, mockFn: TMock): [TMock, () => void];
/**
* Specify a mock function that should be called instead of the
* selector. The selector will stay mocked indefinitely until either
* the clear callback or `clearAllSimpluxMocks` is called.
*
* @param selector - the selector to mock
* @param mockFn - the mock function to use
*
* @returns a function that clears the mock when called
*
* @public
*/
export declare function mockSelector<TState, TArgs extends any[], TReturn, TMock extends (...args: TArgs) => TReturn>(selector: SimpluxSelectorMarker<TState, TArgs, TReturn>, mockFn: TMock): [TMock, () => void];
/**
* Register a function to be called when all mocks are cleared.
*
* @param cleanupFunction - the cleanup function to call
*
* @returns a function that can be called to unregister the function
*
* @public
*/
export declare function registerMockCleanupFunction(cleanupFunction: () => void): () => void;
export { }