{"id":13798693,"url":"https://github.com/stoically/webextensions-api-mock","last_synced_at":"2025-04-14T17:12:19.141Z","repository":{"id":111377243,"uuid":"222238771","full_name":"stoically/webextensions-api-mock","owner":"stoically","description":"WebExtensions API as sinon stubs","archived":false,"fork":false,"pushed_at":"2020-01-29T11:40:35.000Z","size":223,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T17:12:13.973Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stoically.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-11-17T11:39:22.000Z","updated_at":"2024-07-14T18:19:41.000Z","dependencies_parsed_at":"2024-01-05T20:50:16.866Z","dependency_job_id":"2b891202-e454-4203-bdb8-ea51c3bb0009","html_url":"https://github.com/stoically/webextensions-api-mock","commit_stats":{"total_commits":41,"total_committers":2,"mean_commits":20.5,"dds":0.09756097560975607,"last_synced_commit":"0469650f38839e63babd14c1b444023beecc74ea"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoically%2Fwebextensions-api-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoically%2Fwebextensions-api-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoically%2Fwebextensions-api-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoically%2Fwebextensions-api-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stoically","download_url":"https://codeload.github.com/stoically/webextensions-api-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923765,"owners_count":21183953,"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":[],"created_at":"2024-08-04T00:00:50.168Z","updated_at":"2025-04-14T17:12:19.104Z","avatar_url":"https://github.com/stoically.png","language":"TypeScript","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"# WebExtensions API Mock\n\nAutomatically generated [`sinon stubs`](https://sinonjs.org/releases/latest/stubs/), together with types, for the [WebExtensions API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API). Currently based on the Firefox version _72.0.2_ schema. Comes with an API and CLI that lets you update the schema and types to the _latest stable Firefox version_, thanks to [`webextensions-schema`](https://github.com/stoically/webextensions-schema).\n\nTo get globally declared `window.browser` types for production code I'd recommened installing `@types/firefox-webext-browser`, those are automatically generated by [jsmnbom/definitelytyped-firefox-webext-browser](https://github.com/jsmnbom/definitelytyped-firefox-webext-browser)\n\n## Install\n\n```shell\nnpm install --save-dev sinon webextensions-api-mock\n```\n\n**Important**: `sinon` is a peer dependency, so you have to install it yourself. That's because it can otherwise lead to unexpected assertion behavior when sinon does `instanceof` checks internally. It also allows to upgrade sinon without the need to bump the version in `webextensions-api-mock`.\n\n## Usage\n\n```ts\nimport browserMock from 'webextensions-api-mock';\n// or\n// const { default: browserMock } = require('webextensions-api-mock');\n\nconst browser = browserMock();\n```\n\nAll `browser` methods are now [`sinon stubs`](https://sinonjs.org/releases/latest/stubs/) and hence you can use them as usual in your test, e.g. if your production code calls `browser.tabs.create()` you can assert it\n\n```ts\nassert(browser.tabs.create.called);\n```\n\nTo trigger event listeners, you can use the [`yield` method on stubs](https://sinonjs.org/releases/latest/stubs/).\n\n```ts\nbrowser.tabs.onCreated.addListener.yield();\n```\n\nEvery call to `browserMock()` creates a new `browser` object based on a new\n[`sinon sandbox`](https://sinonjs.org/releases/latest/sandbox/). The sinon sandbox itself is exposed as `sinonSandbox` property on the\n`browser` object. So to e.g. reset the history of all browser stubs, you'd call\n\n```ts\nbrowser.sinonSandbox.resetHistory();\n```\n\n## Update schema and types\n\nUpdate the schema and types to the latest available stable Firefox version. Feel\nfree to PR updated schema and types if they're not up-to-date.\n\n### Using API\n\n```ts\nimport { update } from 'webextensions-api-mock';\n// or\n// const { update } = require('webextensions-api-mock');\n\n(async () =\u003e {\n  await update();\n})();\n```\n\n### Using CLI\n\n```\nwebextensions-api-mock update\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstoically%2Fwebextensions-api-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstoically%2Fwebextensions-api-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstoically%2Fwebextensions-api-mock/lists"}