Skip to content

Commit

Permalink
feat: add tabs.onRemoved and tabs.onCreated mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwan Zibaoui committed Nov 23, 2023
1 parent c0b1bbf commit 6d79ad5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions __tests__/tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ describe('browser.tabs', () => {
expect(browser.tabs.onUpdated[method]).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(0);
});

test(`onRemoved.${method}`, () => {
const callback = jest.fn();
expect(jest.isMockFunction(browser.tabs.onRemoved[method])).toBe(true);
browser.tabs.onRemoved[method](callback);
expect(browser.tabs.onRemoved[method]).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(0);
});

test(`onCreated.${method}`, () => {
const callback = jest.fn();
expect(jest.isMockFunction(browser.tabs.onCreated[method])).toBe(true);
browser.tabs.onCreated[method](callback);
expect(browser.tabs.onCreated[method]).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(0);
});
});
test('reload', (done) => {
const callback = jest.fn(() => done());
Expand Down
10 changes: 10 additions & 0 deletions dist/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ var tabs = {
removeListener: jest.fn(),
hasListener: jest.fn()
},
onRemoved: {
addListener: jest.fn(),
removeListener: jest.fn(),
hasListener: jest.fn()
},
onCreated: {
addListener: jest.fn(),
removeListener: jest.fn(),
hasListener: jest.fn()
},
sendMessage: jest.fn(function (tabId, message, cb) {
onMessageListeners.forEach(function (listener) {
return listener(tabId, message);
Expand Down
10 changes: 10 additions & 0 deletions src/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export const tabs = {
removeListener: jest.fn(),
hasListener: jest.fn(),
},
onRemoved: {
addListener: jest.fn(),
removeListener: jest.fn(),
hasListener: jest.fn(),
},
onCreated: {
addListener: jest.fn(),
removeListener: jest.fn(),
hasListener: jest.fn(),
},
sendMessage: jest.fn((tabId, message, cb) => {
onMessageListeners.forEach((listener) => listener(tabId, message));
if (cb !== undefined) {
Expand Down

0 comments on commit 6d79ad5

Please sign in to comment.