You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

jest-webextension-mock

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-webextension-mock

Mock the components of a WebExtension


Version published
Weekly downloads
20K
increased by4.51%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

npm npm Codecov Greenkeeper badge Twitter

Install

For npm:

npm i --save-dev jest-webextension-mock

For yarn:

yarn add --dev jest-webextension-mock

Setup

Require module directly

In your package.json under the jest section add the setupFiles attribute with this module name.

"jest": {
  "setupFiles": [
    "jest-webextension-mock"
  ]
}

Use setup file

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"
  ]
}

Usage

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);
  });
});

Development

npm install
npm test

Publish

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

Package last updated on 03 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc