RxSandbox is a dedicated testing utility for RxJS Observables, employing a Domain Specific Language (DSL) based on marble diagrams to simplify assertions over virtual time. The current stable version, 2.0.5, is designed specifically for RxJS 7.0.1 and newer, while earlier major versions (1.x) supported RxJS 6.x, and pre-1.x versions accommodated RxJS 5. The project is actively maintained, though its development cadence is primarily tied to upstream RxJS releases rather than continuous feature additions, as it's considered feature-complete. It differentiates itself from the core RxJS `TestScheduler` by offering an extended marble diagram DSL, requiring near-zero configuration, operating independently of specific test frameworks, and supporting flexible `TestMessage` creation for granular testing scenarios.
npm install rx-sandboxVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing `rx-sandbox` and using its `cold`, `hot`, `expectObservable`, and `expectSubscriptions` methods with marble diagrams to test RxJS operators and observable lifecycles.
Ensure your project's `rxjs` dependency is `^7.0.1` or higher when using `rx-sandbox@2.x`. For projects still on RxJS 6.x, use `rx-sandbox@1.x`. For RxJS 5.x, refer to pre-1.x versions of `rx-sandbox`.
Upgrade your Node.js environment to a version supporting ES2015+ (e.g., Node.js 12 or newer). If targeting browsers, ensure your build process includes transpilation to ES2015+ or a compatible target.
Consult the `rx-sandbox` documentation for its precise marble diagram token definitions, particularly if you are accustomed to RxJS's native `TestScheduler` or migrating existing tests.
Verify that your `rxjs` peer dependency (`^7.x`) matches `rx-sandbox@2.x`. Ensure correct RxJS import paths; for RxJS 7, many creation functions like `of` are direct exports from `rxjs`, while operators like `map` are from `rxjs/operators`.
To resolve this, configure your `package.json` with `"type": "module"`, use `.mjs` file extensions, or set up a transpiler (like Babel or TypeScript) to convert ES Modules to CommonJS if targeting a legacy Node.js environment. For direct execution of TypeScript, `ts-node` can often handle this.
Carefully review both the expected marble diagram string and the actual observable's behavior. Ensure the `value` object passed to `toBe()` or `get()` correctly maps the emitted characters to their corresponding values, and that timing (dashes, parentheses, time progression) is accurate.