3.8.16 • Published 15 days ago

jest-webextension-mock v3.8.16

Weekly downloads
6,089
License
ISC
Repository
github
Last release
15 days ago

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
3.8.16

15 days ago

3.8.14

15 days ago

3.8.15

15 days ago

3.8.12

16 days ago

3.8.13

15 days ago

3.8.11

16 days ago

3.8.9

1 year ago

3.8.8

1 year ago

3.8.0

1 year ago

3.8.4

1 year ago

3.8.3

1 year ago

3.8.2

1 year ago

3.8.1

1 year ago

3.8.7

1 year ago

3.8.6

1 year ago

3.8.5

1 year ago

3.7.22

2 years ago

3.7.20

2 years ago

3.7.21

2 years ago

3.7.19

3 years ago

3.7.18

3 years ago

3.7.15

3 years ago

3.7.16

3 years ago

3.7.17

3 years ago

3.7.13

3 years ago

3.7.14

3 years ago

3.7.11

3 years ago

3.7.12

3 years ago

3.7.10

3 years ago

3.7.9

3 years ago

3.7.8

3 years ago

3.7.7

3 years ago

3.7.5

3 years ago

3.7.6

3 years ago

3.7.4

3 years ago

3.7.1

4 years ago

3.7.3

4 years ago

3.7.2

4 years ago

3.7.0

4 years ago

3.6.1

4 years ago

3.6.0

4 years ago

3.5.3

4 years ago

3.5.2

4 years ago

3.5.1

4 years ago

3.5.4

4 years ago

3.5.0

6 years ago

3.4.0

6 years ago

3.3.0

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago