{"id":15598176,"url":"https://github.com/boneskull/unexpected-eventemitter","last_synced_at":"2025-09-13T18:33:20.196Z","repository":{"id":18312609,"uuid":"83997007","full_name":"boneskull/unexpected-eventemitter","owner":"boneskull","description":"EventEmitter assertions for Unexpected","archived":false,"fork":false,"pushed_at":"2024-12-28T14:04:12.000Z","size":888,"stargazers_count":4,"open_issues_count":13,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-28T15:17:46.743Z","etag":null,"topics":["assertion-library","assertions","ee","eventemitter","nodejs","unexpected"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boneskull.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-05T19:42:20.000Z","updated_at":"2023-08-09T03:31:12.000Z","dependencies_parsed_at":"2023-12-21T21:22:50.143Z","dependency_job_id":"75e3c434-356d-4074-9a90-1c29b1729439","html_url":"https://github.com/boneskull/unexpected-eventemitter","commit_stats":{"total_commits":159,"total_committers":3,"mean_commits":53.0,"dds":"0.37735849056603776","last_synced_commit":"fcae3bd59c0354d119b50d83a1d0d71b5f066f05"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Funexpected-eventemitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Funexpected-eventemitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Funexpected-eventemitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Funexpected-eventemitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boneskull","download_url":"https://codeload.github.com/boneskull/unexpected-eventemitter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232902874,"owners_count":18594356,"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":["assertion-library","assertions","ee","eventemitter","nodejs","unexpected"],"created_at":"2024-10-03T01:29:39.739Z","updated_at":"2025-01-07T16:11:21.811Z","avatar_url":"https://github.com/boneskull.png","language":"JavaScript","readme":"# unexpected-eventemitter\n\n\u003e [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) assertions for [Unexpected](http://unexpected.js.org/)\n\n## Installation\n\n```shell\n$ npm i unexpected unexpected-eventemitter --save-dev\n```\n\n- This package requires Node.js v14+ _or_ a browser supporting ES6.\n- [unexpected](http://unexpected.js.org) v10+ is a _peer dependency_ of this package.\n- In a browser, this module is exposed as `globalThis.unexpectedEventEmitter` or `window.unexpectedEventEmitter`.\n\n## Example\n\n```js\nimport unexpected from 'unexpected';\nimport unexpectedEventEmitter from 'unexpected-eventemitter';\nimport {EventEmitter} from 'node:events';\n\nconst expect = unexpected.clone().use(unexpectedEventEmitter);\n\nconst ee = new EventEmitter();\n\n// \"to emit from\" with sync function\nexpect(\n  () =\u003e {\n    ee.emit('foo', {bar: 'baz'});\n  },\n  'to emit from',\n  ee,\n  'foo',\n  {\n    bar: 'baz',\n  }\n); // ok\n\n// \"to emit from\" with async function\nexpect(\n  async () =\u003e {\n    await somethingAsync();\n    ee.emit('foo', {bar: 'baz'});\n  },\n  'to emit from',\n  ee,\n  'foo',\n  {\n    bar: 'baz',\n  }\n); // ok\n\n// \"to emit from\" with Promise\nexpect(\n  somethingAsync().then(() =\u003e {\n    ee.emit('foo', {bar: 'baz'});\n  }),\n  'to emit from',\n  ee,\n  'foo',\n  {\n    bar: 'baz',\n  }\n); // ok\n\n// \"not to emit from\" with async function\nexpect(\n  async () =\u003e {\n    await somethingAsync();\n    ee.emit('foo', {bar: 'baz'});\n  },\n  'not to emit from',\n  ee,\n  'foo'\n); // assertion failure!\n\n// \"to emit with error from\"\nconst err = new Error('uh oh');\nexpect(\n  Promise.resolve().then(() =\u003e {\n    ee.emit('foo', {bar: 'baz'});\n    throw err;\n  }),\n  'to emit with error from',\n  ee,\n  'foo',\n  err\n); // ok\n```\n\n## Assertions\n\n### `to emit from`\n\n`\u003cfunction|Promise\u003e [not] to emit from \u003cEventEmitter\u003e \u003cstring\u003e \u003cany*\u003e`\n\n- `\u003cfunction|Promise\u003e` may be a Promise, async, or synchronous function\n- `\u003cEventEmitter\u003e` may be a duck-typed Node.js [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)\n- `\u003cstring\u003e` is the event name\n- `\u003cany*\u003e` corresponds to _zero (0) or more_ values which may be emitted. Do not use an array unless you expect the value to be an array!\n- An `EventEmitter` emitting _more_ values than expected _will not_ fail an assertion.\n- Values are checked with [\"to satisfy\"](http://unexpected.js.org/assertions/any/to-satisfy/) for flexibility.\n\n### `to emit with error from`\n\n`\u003cfunction|Promise\u003e to emit with error from \u003cError\u003e \u003cEventEmitter\u003e \u003cstring\u003e \u003cany*\u003e`\n\n- Use when the subject `\u003cfunction|Promise\u003e` emits, but _also_ throws or rejects.\n- A strict equality check is made against `Error`\n- There is no converse of this assertion; you cannot use `[not]`.\n\n## Contributing\n\nPlease use the [Conventional Commits](https://www.conventionalcommits.org) commit message format.\n\n## Related Projects\n\n- [unexpected-events](https://npm.im/unexpected-events): Provides an alternative syntax, with the ability to test multiple events at once\n\n## License\n\n:copyright: 2017 [Christopher Hiller](https://boneskull.com). Licensed Apache-2.0.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboneskull%2Funexpected-eventemitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboneskull%2Funexpected-eventemitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboneskull%2Funexpected-eventemitter/lists"}