{"id":20657465,"url":"https://github.com/kefirjs/chai-kefir","last_synced_at":"2026-07-02T10:32:08.327Z","repository":{"id":26276727,"uuid":"107821962","full_name":"kefirjs/chai-kefir","owner":"kefirjs","description":"Chai plugin for asserting on Kefir Observables.","archived":false,"fork":false,"pushed_at":"2023-01-16T08:01:01.000Z","size":220,"stargazers_count":0,"open_issues_count":13,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T20:15:27.715Z","etag":null,"topics":["chai","chai-plugin","javascript","kefir","kefir-observables","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kefirjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-21T23:01:13.000Z","updated_at":"2021-07-05T13:44:18.000Z","dependencies_parsed_at":"2023-01-17T00:30:54.950Z","dependency_job_id":null,"html_url":"https://github.com/kefirjs/chai-kefir","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kefirjs%2Fchai-kefir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kefirjs%2Fchai-kefir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kefirjs%2Fchai-kefir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kefirjs%2Fchai-kefir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kefirjs","download_url":"https://codeload.github.com/kefirjs/chai-kefir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242768072,"owners_count":20182098,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chai","chai-plugin","javascript","kefir","kefir-observables","unit-testing"],"created_at":"2024-11-16T18:20:55.115Z","updated_at":"2026-07-02T10:32:08.277Z","avatar_url":"https://github.com/kefirjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chai-kefir\n\nChai plugin for asserting on Kefir Observables.\n\n[![Build Status](https://travis-ci.org/kefirjs/chai-kefir.svg?branch=master)](https://travis-ci.org/kefirjs/chai-kefir)\n\n---\n\n## How to Use\n\nInstall with npm:\n\n```bash\nnpm i --save-dev chai-kefir\n```\n\nAt the top of your tests, import `chai-kefir` and `kefir` and register Kefir:\n\n```js\nimport Kefir from 'kefir';\nimport { use } from 'chai';\nimport chaiKefir from 'chai-kefir';\n```\n\nIf you're not using ESModules, make sure you grab the `default` property:\n\n```js\nconst Kefir = require('kefir');\nconst { use } = require('chai');\nconst chaiKefir = require('chai-kefir').default;\n```\n\nAt the top of your test file, use the exported factory function to create the plugin and register it with `chai`:\n\n```js\nconst { plugin, activate, send, stream, prop, pool } = chaiKefir(Kefir);\nuse(plugin);\n```\n\nAll of the exported functions enable you to interact with Kefir Observables without needing to directly connect them to real or mock sources.\n\n---\n\n# API\n\n## `Factory: (Kefir) =\u003e PluginHelpers`\n\nThe default export is a factory function that takes the application's Kefir instance returns an object of plugin helpers. Those helpers are documented below.\n\n## `PluginHelpers`\n\n### `plugin: (chai, utils) =\u003e void`\n\nThe `plugin` function registers `chai-kefir`'s assertions with `chai`. This function should be passed to `chai`'s `use` function.\n\n### `activate: (obs: Kefir.Observable) =\u003e void`\n\n`activate` is a simple helper function to turn a stream on.\n\n### `deactivate: (obs: Kefir.Observable) =\u003e void`\n\n`deactivate` is a simple helper function to turn a stream off. It can turn off streams that were activated with `activate`. Streams turned on through other means (direct call to `on{Value|Error|End|Any}`, use of `observe`, etc.) need to be deactivated through their complementary mechanisms.\n\n### `send: (obs: Kefir.Observable, values: Array\u003cEvent\u003cT\u003e\u003e) =\u003e obs`\n\n`send` is a helper function for emitting values into a given observable. Note that the second parameter is an array of values to emit from the observable. The `Event` is generated by the `value`, `error`, and `end` functions. For all three of these functions, the optional `options` object is not needed.\n\n### `value: (value, options: ?{ current }) =\u003e Event\u003cValue\u003e`\n### `error: (error, options: ?{ current }) =\u003e Event\u003cError\u003e`\n### `end: (options: ?{ current }) =\u003e Event\u003cEnd\u003e`\n\n`value` and `error` take a value or error and an optional `options` object and return an `Event` object that can be passed to `send`, `emit`, or `emitInTime`. `end` does not take this value, as the `end` event in Kefir does not send a value with it.\n\nWhen passing to `send`, the `options` object is ignored. `options` is used by `emit` and `emitInTime` (both described below) to determine whether the event should be treated as a `Kefir.Property`'s current event, error, or end.\n\n### `stream: () =\u003e Kefir.Stream`\n### `prop: () =\u003e Kefir.Property`\n### `pool: () =\u003e Kefir.Pool`\n\n`stream`, `prop`, and `pool` are helper functions to create empty streams, properties, and pools. These can be used as mock sources to send values into. They have no other behavior.\n\n## Assertions\n\n### `observable`\n\nAsserts whether the expected value is a `Kefir.Observable`. For the other assertions, we recommend chaining off `observable`. `property` below requires it; the rest should for consistency.\n\n```js\nexpect(obs).to.be.an.observable();\n```\n\n### `property`\n\nAsserts whether the expected value is a `Kefir.Property`. Must be chained with `observable`.\n\n```js\nexpect(obs).to.be.an.observable.property();\n```\n\n### `stream`\n\nAsserts whether the expected value is a `Kefir.Stream`.\n\n```js\nexpect(obs).to.be.an.observable.stream();\n```\n\n### `pool`\n\nAsserts whether the expected value is a `Kefir.Pool`.\n\n```js\nexpect(obs).to.be.an.observable.pool();\n```\n\n### `active`\n\nAsserts whether the expected value is an observable that is active.\n\n```js\nexpect(obs).to.be.an.active.observable();\n```\n\n### `emit`\n\nAsserts whether the provided observable emits the expected values synchronously. `emit` takes an array of values to match against and expects them to deep equal the values in the correct order.\n\nAccepts an optional callback to be called after the observable is activated. This is because values emitted into the observable before it's passed to `chai` will not be emitted into the assertion, unless it's a Property.\n\n```js\nexpect(obs).to.emit([value(1), error(new Error('whoops!')), end()], () =\u003e {\n    send(obs, [value(1), error(new Error('whoops!')), end()]);\n});\n```\n\nIf `obs` is a `Kefir.Property` with a current value, the expected values should get the options object with `current: true`. Note that given how Properties work, only the last value is current.\n\n```js\nsend(obs, [value(1)]);\nsend(obs, [value(2)]);\nexpect(obs).to.emit([value(2, { current: true }), end()], () =\u003e {\n    send(obs, [end()]);\n});\n```\n\nThese rules also apply to `emitInTime`.\n\n### `emitInTime`\n\nAssets whether the provided emits the values correctly over time. Uses `lolex` behind the scenes to take over JavaScripts timers, allowing you to assert against the times the values are emitted. The expected value should be an array of tuples, where the first value is the time and the second is the value emitted.\n\n```js\nconst expected = [\n    [0, value(1)],\n    [10, error(new Error('whoops!'))],\n    [20, end()]\n]\n```\n\nAccepts a callback which is passed both a simple `tick` function as well as the full `lolex` `clock`. `tick` advances the internal timer by the provided ms. `clock` is documented [here][clock].\n\n```js\nexpect(obs).to.emit(expected, (tick, clock) =\u003e {\n    send(obs, [value(1)]);\n    tick(10);\n    send(obs, [error(new Error('whoops!'))]);\n    tick(10);\n    send(obs, [end()]);\n});\n```\n\n`emitInTime` also accepts an optional configuration object after the callback. That object takes the following options:\n\n* `reverseSimultaneous: bool`: Indicates whether callbacks scheduled for the same time should be called in reverse. This is an advanced use case to check if your implementation handles a common browser bug. See this [issue][timer-issue] for more information. This is handled correctly by Kefir's built-in methods, so unless you're using timers in your implementation, this mostly isn't necessary.\n\n  [clock]: https://github.com/sinonjs/lolex/#var-id--clocksettimeoutcallback-timeout\n  [timer-issue]: https://github.com/sinonjs/lolex/issues/24\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkefirjs%2Fchai-kefir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkefirjs%2Fchai-kefir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkefirjs%2Fchai-kefir/lists"}