
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
jest-webextension-mock
Advanced tools
For npm:
npm i --save-dev jest-webextension-mock
For yarn:
yarn add --dev jest-webextension-mock
In your package.json
under the jest
section add the setupFiles
attribute with this module name.
"jest": {
"setupFiles": [
"jest-webextension-mock"
]
}
Alternatively you can create a new setup file and require this module.
__setups__/chrome.js
require('jest-webextension-mock');
And add that file to your setupFiles
:
"jest": {
"setupFiles": [
"./__setups__/chrome.js"
]
}
Use this module to check that API calls were made when expected.
describe('your function to test', () => {
it('should have called a webextension API', () => {
yourFunctionToTest();
expect(chrome.tabs.update).toHaveBeenCalled();
});
});
Check the API was called with certain parameters.
describe('your function to test', () => {
it('should have called a webextension API', () => {
yourFunctionToTest();
expect(chrome.tabs.update).toHaveBeenCalledWith({
url: 'https://example.com/'
});
});
});
And you can reset the API mocks to ensure APIs are only called when needed.
beforeEach(() => {
browser.geckoProfiler.start.mockClear();
browser.geckoProfiler.stop.mockClear();
});
it('should toggle the profiler on from stopped', () => {
const store = mockStore(reducer(undefined, {}));
const expectedActions = [
{ type: 'PROFILER_START', status: 'start' },
{ type: 'PROFILER_START', status: 'done' },
];
return store.dispatch(actions.toggle()).then(() => {
expect(browser.geckoProfiler.start).toHaveBeenCalledTimes(1);
expect(store.getActions()).toEqual(expectedActions);
});
});
npm install
npm test
4.0.0
FAQs
Mock the components of a WebExtension
The npm package jest-webextension-mock receives a total of 16,474 weekly downloads. As such, jest-webextension-mock popularity was classified as popular.
We found that jest-webextension-mock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.