Employee Spotlight
From Academia to Industry
Philipp Burckhardt recounts his journey from childhood computer fascinations, to building an e-learning platform at Carnegie Mellon University, and on to his current role at Socket.
jest-webextension-mock
Advanced tools
Readme
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
Publishing new releases is automated via the GitHub Action https://github.com/mikeal/merge-release tool.
To ensure your feature is properly released prefix your commit message with feat
for any new feature. For example: feat: new API
and this will bump the minor release number. All other changes will be assumed as patch releases unless you include the string BREAKING CHANGE
in your commit message or description which will trigger a new major release. (do not do this unless absolutely required)
FAQs
Mock the components of a WebExtension
The npm package jest-webextension-mock receives a total of 16,085 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.
Employee Spotlight
Philipp Burckhardt recounts his journey from childhood computer fascinations, to building an e-learning platform at Carnegie Mellon University, and on to his current role at Socket.
Security News
Git dependencies in open source packages can introduce significant risks, including lack of version control, stability issues, dependency drift, and difficulty in auditing, making them potential targets for supply chain attacks.
Security News
Node.js has added experimental support for TypeScript, a move that highlights the growing importance of TypeScript in modern development.