3.4.5 • Published 1 month ago

@reatom/testing v3.4.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

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

1 month ago

3.4.4

8 months ago

3.4.3

8 months ago

3.4.2

10 months ago

3.4.1

10 months ago

3.4.0

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

2 years ago