Registry / testing / kefir-test-utils

kefir-test-utils

JSON →
library2.0.0jsnpmunverified

Kefir-test-utils is a dedicated, framework-agnostic library providing a set of utilities specifically designed for testing Kefir.js observables. It enables developers to write robust unit tests for reactive streams by offering tools to control time, watch observable emissions, and assert their behavior over virtual timelines. The current stable version is 2.0.0, released in late 2023, following a period of maintenance and dependency upgrades. While its release cadence appears measured, recent updates indicate active development, focusing on modern JavaScript environments and dependency health. Key differentiators include its tight integration and specialization for the Kefir.js ecosystem, having been extracted from `chai-kefir` to offer a standalone, reusable set of testing primitives without tying to a specific assertion library or test framework. It is crucial for anyone building complex reactive applications with Kefir.js who needs precise control over testing asynchronous stream logic, offering a structured approach to virtual time testing that is typically more challenging with general-purpose testing tools.

npm install kefir-test-utils
INSTALL
IMPORT
SIG · KEFIR-TEST-UTILS
K
kefir-test-utils
testingjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

withTime
import { withTime } from 'kefir-test-utils'
const withTime = require('kefir-test-utils').withTime
Primary utility for running tests with virtual time. ESM imports are preferred since v2.0.0 dropped Node.js v10 support, moving towards modern JavaScript practices.
watch
import { watch } from 'kefir-test-utils'
const watch = require('kefir-test-utils').watch
Used to observe and collect emissions from Kefir observables within a test context for assertion.
watchWithTime
import { watchWithTime } from 'kefir-test-utils'
import watchWithTime from 'kefir-test-utils'
A convenience function combining `withTime` and `watch` for common scenarios. It is a named export, despite its singular name suggesting a potential default export.

Demonstrates basic usage of `withTime` and `watch` to test a Kefir observable's emissions and completion over a virtual timeline, including how to handle and assert error scenarios.

import * as Kefir from 'kefir'; import { withTime, watch } from 'kefir-test-utils'; describe('Kefir-test-utils example', () => { it('should test a simple observable with virtual time', () => { withTime((tick) => { // Create a Kefir stream that emits 1, 2, 3 sequentially with 100ms intervals const stream = Kefir.sequentially(100, [1, 2, 3]); // Use `watch` to collect events from the stream const watcher = watch(stream); // Assert initial state expect(watcher.next).toEqual([]); // Advance virtual time tick(50); // 50ms passed expect(watcher.next).toEqual([]); // No emissions yet tick(50); // Total 100ms passed expect(watcher.next).toEqual([1]); // First emission received tick(100); // Total 200ms passed expect(watcher.next).toEqual([1, 2]); // Second emission received tick(100); // Total 300ms passed expect(watcher.next).toEqual([1, 2, 3]); // All emissions received expect(watcher.complete).toEqual(true); // Stream completed }); }); it('should handle errors in a stream gracefully', () => { withTime((tick) => { // Create a stream that emits 1, then an error, which is caught and mapped to a message const errorStream = Kefir.sequentially(50, [1]) .concat(Kefir.later(50, new Error('Simulated Error'))) .flatMapErrors(e => Kefir.constant(e.message)); // Catch error and emit message const watcher = watch(errorStream); tick(50); expect(watcher.next).toEqual([1]); tick(50); // The error was caught and its message was emitted as a 'next' event expect(watcher.next).toEqual([1, 'Simulated Error']); expect(watcher.error).toEqual([]); // No actual error was propagated by `flatMapErrors` expect(watcher.complete).toEqual(true); }); }); });
Debug
Known issues
breakingVersion 2.0.0 includes an internal upgrade to its fake timers dependency, which might subtly alter timing behavior or test interaction patterns if previous versions relied on specific internal timer implementations. This could necessitate minor adjustments to tests with very precise timing assertions.
fix
Review existing tests, especially those with precise timing assertions or complex virtual time interactions, and adjust expectations if behavior subtly changes due to the underlying fake timer implementation's update.
affects: >=2.0.0
breakingSupport for Node.js v10 has been dropped in version 2.0.0, aligning the library with more modern Node.js runtimes. Running on Node.js v10 or earlier will result in compatibility errors.
fix
Ensure your project's Node.js environment is v12 or higher. Upgrade Node.js if necessary to avoid compatibility issues and leverage modern language features.
affects: >=2.0.0
gotchaThe `kefir` package is a peer dependency of `kefir-test-utils`. It must be installed separately in your project alongside `kefir-test-utils` for the library to function correctly, as it provides the core observable primitives being tested.
fix
Install `kefir` in your project's dependencies: `npm install kefir` or `yarn add kefir`.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'kefir'
The peer dependency 'kefir' is not installed in the project, which is required by `kefir-test-utils`.
fix
Install the 'kefir' package: `npm install kefir` or `yarn add kefir`.
TypeError: (0, _kefirTestUtils.withTime) is not a function
This error typically indicates incorrect CommonJS `require` syntax when trying to access a named export, or attempting to use a default import for a named export in an ESM context.
fix
For CommonJS environments, ensure you use `const { withTime } = require('kefir-test-utils');`. For ESM (recommended since v2.0.0), use `import { withTime } from 'kefir-test-utils';`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
kefirrequiredPeer dependency, required for creating and testing observables.
Agent activity
4 hits · last 30 days
node
4
Resources
kefir-test-utils — npm install kefir-test-utils · libregistry