Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-webextension-mock

Package Overview
Dependencies
Maintainers
0
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-webextension-mock - npm Package Compare versions

Comparing version 3.9.1 to 4.0.0

16

__tests__/browserAction.test.js

@@ -8,4 +8,4 @@ describe('browser.browserAction', () => {

});
test('getTitle', (done) => {
const callback = jest.fn(() => done());
test('getTitle', () => {
const callback = jest.fn();
expect(jest.isMockFunction(browser.browserAction.getTitle)).toBe(true);

@@ -33,4 +33,4 @@ browser.browserAction.getTitle({}, callback);

});
test('getPopup', (done) => {
const callback = jest.fn(() => done());
test('getPopup', () => {
const callback = jest.fn();
expect(jest.isMockFunction(browser.browserAction.getPopup)).toBe(true);

@@ -51,4 +51,4 @@ browser.browserAction.getPopup({}, callback);

});
test('getBadgeText', (done) => {
const callback = jest.fn(() => done());
test('getBadgeText', () => {
const callback = jest.fn();
expect(jest.isMockFunction(browser.browserAction.getBadgeText)).toBe(true);

@@ -75,4 +75,4 @@ browser.browserAction.getBadgeText({}, callback);

});
test('getBadgeBackgroundColor', (done) => {
const callback = jest.fn(() => done());
test('getBadgeBackgroundColor', () => {
const callback = jest.fn();
expect(

@@ -79,0 +79,0 @@ jest.isMockFunction(browser.browserAction.getBadgeBackgroundColor)

describe('browser.commands', () => {
test('getAll', (done) => {
const callback = jest.fn(() => done());
test('getAll', () => {
const callback = jest.fn();
expect(jest.isMockFunction(browser.commands.getAll)).toBe(true);

@@ -5,0 +5,0 @@ browser.commands.getAll(callback);

describe('browser.downloads', () => {
test('acceptDanger', (done) => {
test('acceptDanger', () => {
const downloadId = 1;
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -9,3 +9,6 @@ expect(jest.isMockFunction(chrome.downloads.acceptDanger)).toBe(true);

expect(chrome.downloads.acceptDanger).toHaveBeenCalledTimes(1);
expect(chrome.downloads.acceptDanger).toHaveBeenLastCalledWith(downloadId, callback);
expect(chrome.downloads.acceptDanger).toHaveBeenLastCalledWith(
downloadId,
callback
);
expect(callback).toHaveBeenCalled();

@@ -18,5 +21,5 @@ });

});
test('cancel', (done) => {
test('cancel', () => {
const downloadId = 1;
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -26,3 +29,6 @@ expect(jest.isMockFunction(chrome.downloads.cancel)).toBe(true);

expect(chrome.downloads.cancel).toHaveBeenCalledTimes(1);
expect(chrome.downloads.cancel).toHaveBeenLastCalledWith(downloadId, callback);
expect(chrome.downloads.cancel).toHaveBeenLastCalledWith(
downloadId,
callback
);
expect(callback).toHaveBeenCalled();

@@ -35,5 +41,5 @@ });

});
test('download', (done) => {
test('download', () => {
const options = {};
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -43,3 +49,6 @@ expect(jest.isMockFunction(chrome.downloads.download)).toBe(true);

expect(chrome.downloads.download).toHaveBeenCalledTimes(1);
expect(chrome.downloads.download).toHaveBeenLastCalledWith(options, callback);
expect(chrome.downloads.download).toHaveBeenLastCalledWith(
options,
callback
);
expect(callback).toHaveBeenCalled();

@@ -52,5 +61,5 @@ });

});
test('erase', (done) => {
test('erase', () => {
const query = {};
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -68,5 +77,5 @@ expect(jest.isMockFunction(chrome.downloads.erase)).toBe(true);

});
test('getFileIcon', (done) => {
test('getFileIcon', () => {
const downloadId = 1;
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -76,3 +85,6 @@ expect(jest.isMockFunction(chrome.downloads.getFileIcon)).toBe(true);

expect(chrome.downloads.getFileIcon).toHaveBeenCalledTimes(1);
expect(chrome.downloads.getFileIcon).toHaveBeenLastCalledWith(downloadId, callback);
expect(chrome.downloads.getFileIcon).toHaveBeenLastCalledWith(
downloadId,
callback
);
expect(callback).toHaveBeenCalled();

@@ -93,5 +105,5 @@ });

});
test('pause', (done) => {
test('pause', () => {
const downloadId = 1;
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -101,3 +113,6 @@ expect(jest.isMockFunction(chrome.downloads.pause)).toBe(true);

expect(chrome.downloads.pause).toHaveBeenCalledTimes(1);
expect(chrome.downloads.pause).toHaveBeenLastCalledWith(downloadId, callback);
expect(chrome.downloads.pause).toHaveBeenLastCalledWith(
downloadId,
callback
);
expect(callback).toHaveBeenCalled();

@@ -110,5 +125,5 @@ });

});
test('removeFile', (done) => {
test('removeFile', () => {
const downloadId = 1;
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -118,3 +133,6 @@ expect(jest.isMockFunction(chrome.downloads.removeFile)).toBe(true);

expect(chrome.downloads.removeFile).toHaveBeenCalledTimes(1);
expect(chrome.downloads.removeFile).toHaveBeenLastCalledWith(downloadId, callback);
expect(chrome.downloads.removeFile).toHaveBeenLastCalledWith(
downloadId,
callback
);
expect(callback).toHaveBeenCalled();

@@ -127,5 +145,5 @@ });

});
test('resume', (done) => {
test('resume', () => {
const downloadId = 1;
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -135,3 +153,6 @@ expect(jest.isMockFunction(chrome.downloads.resume)).toBe(true);

expect(chrome.downloads.resume).toHaveBeenCalledTimes(1);
expect(chrome.downloads.resume).toHaveBeenLastCalledWith(downloadId, callback);
expect(chrome.downloads.resume).toHaveBeenLastCalledWith(
downloadId,
callback
);
expect(callback).toHaveBeenCalled();

@@ -144,5 +165,5 @@ });

});
test('search', (done) => {
test('search', () => {
const query = {};
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -149,0 +170,0 @@ expect(jest.isMockFunction(chrome.downloads.search)).toBe(true);

describe('chrome.notifications', () => {
test('create', (done) => {
test('create', () => {
const options = { type: 'basic' };
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -34,5 +34,5 @@ expect(jest.isMockFunction(chrome.notifications.create)).toBe(true);

test('update', (done) => {
test('update', () => {
const options = { type: 'basic' };
const callback = jest.fn(() => done());
const callback = jest.fn();

@@ -56,4 +56,4 @@ expect(jest.isMockFunction(chrome.notifications.update)).toBe(true);

test('clear', (done) => {
const callback = jest.fn(() => done());
test('clear', () => {
const callback = jest.fn();

@@ -71,4 +71,4 @@ expect(jest.isMockFunction(chrome.notifications.clear)).toBe(true);

test('getAll', (done) => {
const callback = jest.fn(() => done());
test('getAll', () => {
const callback = jest.fn();

@@ -86,4 +86,4 @@ expect(jest.isMockFunction(chrome.notifications.getAll)).toBe(true);

test('getPermissionLevel', (done) => {
const callback = jest.fn(() => done());
test('getPermissionLevel', () => {
const callback = jest.fn();

@@ -90,0 +90,0 @@ expect(jest.isMockFunction(chrome.notifications.getPermissionLevel)).toBe(

@@ -23,12 +23,15 @@ beforeEach(() => {

});
test('connect.onMessage listener', (done) => {
test('connect.onMessage listener', () => {
const name = 'CONNECT_NAME';
const listener = jest.fn();
const callback = jest.fn();
browser.runtime.connect(name).onMessage.addListener(listener);
browser.runtime.sendMessage({ test: 'message' }, done);
browser.runtime.sendMessage({ test: 'message' }, callback);
expect(listener).toHaveBeenCalledWith({ test: 'message' });
expect(callback).toHaveBeenCalledTimes(1);
});
test('getURL', () => {
const path = 'TEST_PATH';
const extensionOriginURL = globalThis[Symbol.for('jest-webextension-mock')].extensionPath;
const extensionOriginURL =
globalThis[Symbol.for('jest-webextension-mock')].extensionPath;
expect(jest.isMockFunction(browser.runtime.getURL)).toBe(true);

@@ -39,4 +42,4 @@ const respPath = browser.runtime.getURL(path);

});
test('sendMessage', (done) => {
const callback = jest.fn(() => done());
test('sendMessage', () => {
const callback = jest.fn();
expect(jest.isMockFunction(browser.runtime.sendMessage)).toBe(true);

@@ -49,7 +52,9 @@ browser.runtime.sendMessage({ test: 'message' }, callback);

});
test('sendMessage listener', (done) => {
test('sendMessage listener', () => {
const listener = jest.fn();
const callback = jest.fn();
browser.runtime.onMessage.addListener(listener);
browser.runtime.sendMessage({ test: 'message' }, done);
browser.runtime.sendMessage({ test: 'message' }, callback);
expect(listener).toHaveBeenCalledWith({ test: 'message' });
expect(callback).toHaveBeenCalledTimes(1);
});

@@ -91,7 +96,9 @@ test('sendMessage promise', () => {

const callback = jest.fn();
expect(jest.isMockFunction(browser.runtime.onMessageExternal.addListener)).toBe(
true
expect(
jest.isMockFunction(browser.runtime.onMessageExternal.addListener)
).toBe(true);
browser.runtime.onMessageExternal.addListener(callback);
expect(browser.runtime.onMessageExternal.addListener).toHaveBeenCalledTimes(
1
);
browser.runtime.onMessageExternal.addListener(callback);
expect(browser.runtime.onMessageExternal.addListener).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(0);

@@ -101,8 +108,10 @@ });

const callback = jest.fn();
expect(jest.isMockFunction(browser.runtime.onMessageExternal.removeListener)).toBe(
true
);
expect(
jest.isMockFunction(browser.runtime.onMessageExternal.removeListener)
).toBe(true);
browser.runtime.onMessageExternal.removeListener(callback);
expect(browser.runtime.onMessageExternal.hasListener(callback)).toBe(false);
expect(browser.runtime.onMessageExternal.removeListener).toHaveBeenCalledTimes(1);
expect(
browser.runtime.onMessageExternal.removeListener
).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(0);

@@ -112,9 +121,11 @@ });

const callback = jest.fn();
expect(jest.isMockFunction(browser.runtime.onMessageExternal.hasListener)).toBe(
true
);
expect(
jest.isMockFunction(browser.runtime.onMessageExternal.hasListener)
).toBe(true);
browser.runtime.onMessageExternal.addListener(callback);
const returnVal = browser.runtime.onMessageExternal.hasListener(callback);
expect(returnVal).toBe(true);
expect(browser.runtime.onMessageExternal.hasListener).toHaveBeenCalledTimes(1);
expect(browser.runtime.onMessageExternal.hasListener).toHaveBeenCalledTimes(
1
);
expect(callback).toHaveBeenCalledTimes(0);

@@ -121,0 +132,0 @@ });

describe('browser.tabs', () => {
test('get', (done) => {
const callback = jest.fn(() => done());
test('get', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.get)).toBe(true);

@@ -9,4 +9,4 @@ chrome.tabs.get(1, callback);

});
test('getCurrent', (done) => {
const callback = jest.fn(() => done());
test('getCurrent', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.getCurrent)).toBe(true);

@@ -28,4 +28,4 @@ chrome.tabs.getCurrent(callback);

});
test('create', (done) => {
const callback = jest.fn(() => done());
test('create', () => {
const callback = jest.fn();
const props = { pinned: true };

@@ -42,4 +42,4 @@ expect(jest.isMockFunction(chrome.tabs.create)).toBe(true);

});
test('duplicate', (done) => {
const callback = jest.fn(() => done());
test('duplicate', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.duplicate)).toBe(true);

@@ -51,4 +51,4 @@ chrome.tabs.duplicate(1, callback);

});
test('remove', (done) => {
const callback = jest.fn(() => done());
test('remove', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.remove)).toBe(true);

@@ -62,4 +62,4 @@ chrome.tabs.remove([1], callback);

});
test('query', (done) => {
const callback = jest.fn(() => done());
test('query', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.query)).toBe(true);

@@ -71,4 +71,4 @@ chrome.tabs.query({ pinned: true }, callback);

});
test('highlight', (done) => {
const callback = jest.fn(() => done());
test('highlight', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.highlight)).toBe(true);

@@ -79,4 +79,4 @@ chrome.tabs.highlight({}, callback);

});
test('update', (done) => {
const callback = jest.fn(() => done());
test('update', () => {
const callback = jest.fn();
const props = { pinned: true };

@@ -91,4 +91,4 @@ expect(jest.isMockFunction(chrome.tabs.update)).toBe(true);

});
test('move', (done) => {
const callback = jest.fn(() => done());
test('move', () => {
const callback = jest.fn();
const props = { pinned: true };

@@ -130,4 +130,4 @@ expect(jest.isMockFunction(chrome.tabs.move)).toBe(true);

});
test('reload', (done) => {
const callback = jest.fn(() => done());
test('reload', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.reload)).toBe(true);

@@ -140,4 +140,4 @@

});
test('sendMessage', (done) => {
const callback = jest.fn(() => done());
test('sendMessage', () => {
const callback = jest.fn();
expect(jest.isMockFunction(chrome.tabs.sendMessage)).toBe(true);

@@ -150,7 +150,9 @@ chrome.tabs.sendMessage(1, { test: 'message' }, callback);

});
test('sendMessage listener', (done) => {
test('sendMessage listener', () => {
const listener = jest.fn();
const callback = jest.fn();
browser.runtime.onMessage.addListener(listener);
chrome.tabs.sendMessage(1, { test: 'message' }, done);
chrome.tabs.sendMessage(1, { test: 'message' }, callback);
expect(listener).toHaveBeenCalledWith(1, { test: 'message' });
expect(callback).toHaveBeenCalledTimes(1);
});

@@ -157,0 +159,0 @@ test('sendMessage promise', () => {

# jest-webextension-mock
## 4.0.0
### Major Changes
- b8594f9: Drop support for node 14 and 16, add support for node 18 and 22
## 3.9.1

@@ -4,0 +10,0 @@

'use strict';
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return keys;
return t;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return target;
return e;
}
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return obj;
return ("string" === r ? String : Number)(t);
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}

@@ -93,0 +104,0 @@ // https://developer.chrome.com/extensions/omnibox

{
"name": "jest-webextension-mock",
"version": "3.9.1",
"version": "4.0.0",
"description": "Mock the components of a WebExtension",

@@ -21,16 +21,15 @@ "main": "dist/setup.js",

"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@changesets/cli": "^2.27.1",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.5.2",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.5.3",
"prettier": "^2.1.2",
"rollup": "^2.30.0",
"@babel/core": "^7.25.8",
"@babel/preset-env": "^7.25.8",
"@changesets/cli": "^2.27.9",
"babel-jest": "^29.7.0",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"rollup": "^2.79.2",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-watch": "^4.0.0"
"rollup-watch": "^4.3.1"
},

@@ -37,0 +36,0 @@ "jest": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc