3.4.9 • Published 7 months ago
@reatom/testing v3.4.9
Small context wrapper simplify your mocking and testing.
Installation
npm i @reatom/testing
Usage
import { createTestCtx, mockFn } from '@reatom/testing'
export interface TestCtx extends Ctx {
mock<T>(anAtom: Atom<T>, fallback: T): Unsubscribe
mockAction<T>(anAction: Action<any[], T>, cb: Fn<[Ctx], T>): Unsubscribe
subscribeTrack<T, F extends Fn<[T]>>(
anAtom: Atom<T>,
cb?: F,
): F & {
unsubscribe: Unsubscribe
calls: ReturnType<typeof mockFn<[T], any>>['calls']
lastInput: ReturnType<typeof mockFn<[T], any>>['lastInput']
}
}
declare function mockFn<I extends any[], O>(
fn?: (...input: I) => O,
): ((...input: I) => O) & {
calls: Array<{ i: I; o: O }>
lastInput: Fn<[], I[0]>
}