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

3.4.5 • Public • Published

Small context wrapper simplify your mocking and testing.

Installation

npm i @reatom/testing

Usage

We recommend to use uvu as helper library for test description, as it could be used in any runtime (and even browser!) and super fast. To clarify, with uvu you allow to run your test files with node / deno / bun / graalvm / esbuild-kit/tsx and browser just out of the box. But @reatom/testing is not coupled to uvu, you could use any testing framework.

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

Readme

Keywords

none

Package Sidebar

Install

npm i @reatom/testing

Weekly Downloads

46

Version

3.4.5

License

MIT

Unpacked Size

24.7 kB

Total Files

8

Last publish

Collaborators

  • artalar