4.0.0 • Published 7 months ago

jest-webextension-mock v4.0.0

Weekly downloads
6,089
License
ISC
Repository
github
Last release
7 months 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.9.1

7 months ago

4.0.0

7 months ago

3.9.0

1 year ago

3.8.16

1 year ago

3.8.14

1 year ago

3.8.15

1 year ago

3.8.12

1 year ago

3.8.13

1 year ago

3.8.11

1 year ago

3.8.9

2 years ago

3.8.8

2 years ago

3.8.0

3 years ago

3.8.4

3 years ago

3.8.3

3 years ago

3.8.2

3 years ago

3.8.1

3 years ago

3.8.7

3 years ago

3.8.6

3 years ago

3.8.5

3 years ago

3.7.22

3 years ago

3.7.20

3 years ago

3.7.21

3 years ago

3.7.19

4 years ago

3.7.18

4 years ago

3.7.15

4 years ago

3.7.16

4 years ago

3.7.17

4 years ago

3.7.13

4 years ago

3.7.14

4 years ago

3.7.11

4 years ago

3.7.12

4 years ago

3.7.10

4 years ago

3.7.9

4 years ago

3.7.8

4 years ago

3.7.7

4 years ago

3.7.5

5 years ago

3.7.6

5 years ago

3.7.4

5 years ago

3.7.1

5 years ago

3.7.3

5 years ago

3.7.2

5 years ago

3.7.0

5 years ago

3.6.1

5 years ago

3.6.0

5 years ago

3.5.3

5 years ago

3.5.2

5 years ago

3.5.1

5 years ago

3.5.4

5 years ago

3.5.0

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago