{"library":"rxjs-marbles","title":"RxJS Marble Testing","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install rxjs-marbles"],"cli":null},"imports":["import { marbles } from 'rxjs-marbles/mocha';","import { map } from 'rxjs/operators';","import { TestScheduler } from 'rxjs/testing';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { marbles } from \"rxjs-marbles/mocha\";\nimport { map } from \"rxjs/operators\";\nimport { Observable } from 'rxjs';\n\ndescribe(\"rxjs-marbles basic test\", () => {\n\n    it(\"should map values from a hot observable\", marbles(m => {\n        // Define a hot observable source using marble syntax\n        const source =  m.hot(\"--^-a-b-c-|');\n        // Define the subscription timeframe\n        const subs =            \"^-------!\";\n        // Define the expected output after mapping\n        const expected =        \"--b-c-d-|';\n\n        // Apply the map operator to the source observable\n        const destination: Observable<string> = source.pipe(\n            map(value => String.fromCharCode(value.charCodeAt(0) + 1))\n        );\n\n        // Assert that the destination observable matches the expected marble diagram\n        m.expect(destination).toBeObservable(expected);\n        // Assert that the source was subscribed to during the defined 'subs' timeframe\n        m.expect(source).toHaveSubscriptions(subs);\n    }));\n});","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}