rxjs-marbles is a flexible and framework-agnostic library designed for conducting marble tests in RxJS applications. It provides a consistent interface for testing observable streams across various JavaScript testing frameworks, including AVA, Jasmine, Jest, Mocha, and Tape, in both browser and Node.js environments. The library currently targets RxJS version 7.x, as indicated by its peer dependency on `rxjs: ^7.0.0`. Its key differentiator lies in abstracting away framework-specific boilerplate like global setups or `beforeEach`/`afterEach` hooks, allowing developers to focus solely on the marble diagrams. It wraps RxJS's internal `TestScheduler` and exposes similar helper methods, simplifying the process of defining hot/cold observables, subscriptions, and expected outputs using the familiar marble syntax. While no explicit release cadence is stated, the package is actively maintained, with version 7.0.1 being the current stable release. The library ships with TypeScript types, facilitating its use in TypeScript projects.
npm install rxjs-marblesVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic marble test using `rxjs-marbles` with Mocha. It defines a hot observable, applies a transformation, and asserts the output against a marble diagram.
Install a compatible `rxjs` version (e.g., `npm install rxjs@^7.0.0 --save-dev`) or use an `rxjs-marbles` version that targets your existing `rxjs` installation.
Always import `marbles` from the path specific to your test framework, such as `import { marbles } from 'rxjs-marbles/mocha';` or `import { marbles } from 'rxjs-marbles/jest';`.Thoroughly review the official RxJS documentation on 'marble syntax' and 'synchronous assertion' to grasp the intricacies of marble diagram interpretation and test execution.
Ensure your test callback is passed to `marbles`, like `it('should work', marbles(m => { ... }));`.Carefully re-examine your source, subscription, and expected marble diagrams. Use `m.log('label', observable)` to debug and inspect the actual emissions of your observables during the test run.Verify that RxJS operators are imported from `rxjs/operators` (e.g., `import { map } from 'rxjs/operators';`). If using CommonJS, ensure your build setup correctly transpires ESM imports, or use `const { map } = require('rxjs/operators');` if targeting CJS directly (though ESM imports are preferred for modern RxJS).