import { Action, Reducer } from 'redux'; import { SagaIterator } from 'redux-saga'; import * as E from 'redux-saga/effects'; import { Matcher } from './matchers'; import { EffectProviders, StaticProvider } from './providers'; import { EffectApi, EffectApiEx } from './effects' type Timeout = number | false; type TimeoutConfig = { silenceTimeout?: boolean, timeout?: Timeout, }; export type ExpectApiEffects = Pick, 'getContext' | 'setContext' | 'race' | 'take' | 'takeMaybe'> & Pick, 'actionChannel' | 'apply' | 'call' | 'cps' | 'fork' | 'put' | 'putResolve' | 'select' | 'spawn'>; interface RunResult { storeState: any; returnValue: any; allEffects: E.Effect[]; effects: { take: E.TakeEffect[]; takeMaybe: E.TakeEffect[]; put: E.PutEffect[]; putResolve: E.PutEffect[]; race: E.RaceEffect[]; call: E.CallEffect[]; cps: E.CpsEffect[]; fork: E.ForkEffect[]; getContext: E.GetContextEffect[]; select: E.SelectEffect[]; setContext: E.SetContextEffect[]; actionChannel: E.ActionChannelEffect[]; }; toJSON(): Object; } export interface ExpectApi extends ExpectApiEffects { /** default timeout 250ms */ run(timeout?: Timeout | TimeoutConfig): Promise; /** default timeout 250ms */ silentRun(timeout?: Timeout | TimeoutConfig): Promise; provide(newProviders: EffectProviders): ExpectApi; provide(newProviders: (EffectProviders | StaticProvider)[]): ExpectApi; withState(state: S): ExpectApi; withReducer(newReducer: Reducer, initialState?: S): ExpectApi; hasFinalState(state: S): ExpectApi; returns(value: any): ExpectApi; throws(type: any): ExpectApi; delay(time: number): ExpectApi; dispatch(action: A): ExpectApi; not: ExpectApi; } export type TakeHelperProgresser = ( pattern: E.Pattern, saga: Function, ...args: any[] ) => TestApi; export type ThrottleHelperProgresser = ( delayTime: number, pattern: E.Pattern, saga: Function, ...args: any[] ) => TestApi; export type RetryHelperProgresser = ( maxTries: number, delayLength: number, fn: Function, ...args: any[] ) => TestApi; export type TestApiEffects = Pick< EffectApi, 'actionChannel' | 'apply' | 'cps' | 'getContext' | 'put' | 'putResolve' | 'race' | 'select' | 'call' | 'fork' | 'setContext' | 'spawn' | 'take' | 'takeMaybe' | 'all' | 'cancel' | 'cancelled' | 'flush' | 'join' | 'delay'>; export interface TestApi { next(...args: any[]): TestApiWithEffectsTesters; finish(...args: any[]): TestApiWithEffectsTesters; back(n?: number): TestApi; save(s: string): TestApi; restore(s: string): TestApi; restart(...args: any[]): TestApi; throw(error: Error): TestApiWithEffectsTesters; takeEvery: TakeHelperProgresser; takeLatest: TakeHelperProgresser; takeLeading: TakeHelperProgresser; throttle: ThrottleHelperProgresser; retry: RetryHelperProgresser; } export type TestApiWithEffectsTesters = TestApi & TestApiEffects & { /** deprecated */ takeEveryFork(action: E.Pattern, fn: Function, ...args: any[]): TestApi; /** deprecated */ takeLatestFork(action: E.Pattern, fn: Function, ...args: any[]): TestApi; /** deprecated */ throttleFork(ms: number, action: E.Pattern, fn: Function, ...args: any[]): TestApi; takeEveryEffect(action: E.Pattern, fn: Function, ...args: any[]): TestApi; takeLatestEffect(action: E.Pattern, fn: Function, ...args: any[]): TestApi; takeLeadingEffect(action: E.Pattern, fn: Function, ...args: any[]): TestApi; throttleEffect(ms: number, action: E.Pattern, fn: Function, ...args: any[]): TestApi; retryEffect(maxTries: number, delayLength: number, fn: Function, ...args: any[]): TestApi; is(expectation: V): TestApi; inspect(expectation: (yieldedValue: V) => void): TestApi; isDone(): TestApi; returns(returnValue: V): TestApi; }; export type SagaType = (...params: Args) => SagaIterator | IterableIterator; export const expectSaga: (( generator: SagaType, ...sagaArgs: Args ) => ExpectApi) & { DEFAULT_TIMEOUT: number }; export const testSaga: ( generator: SagaType, ...sagaArgs: Args ) => TestApi;