Skip to content

Commit

Permalink
fix: storage.get methods throwing when not provided with an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyMarou committed Apr 23, 2024
1 parent 7695b26 commit 03315a8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# jest-webextension-mock

## 3.8.16

### Patch Changes

- Fix storage.get method throwing when not provided with a key

## 3.8.15

### Patch Changes
Expand Down
3 changes: 3 additions & 0 deletions __tests__/storage.test.js
Expand Up @@ -55,6 +55,9 @@ describe('browser.storage', () => {
expect(e.message).toBe('Wrong key given');
}
});
test('an undefined key', () => {
return expect(storage.get()).resolves.toEqual({});
});
afterEach(() => {
expect(storage.get).toHaveBeenCalledTimes(1);
storage.clear();
Expand Down
6 changes: 3 additions & 3 deletions dist/setup.js
Expand Up @@ -283,7 +283,7 @@ function resolveKey(key, store) {
var storage = {
sync: {
get: jest.fn(function (id, cb) {
var result = id === null ? syncStore : resolveKey(id, syncStore);
var result = id === null || id === undefined ? syncStore : resolveKey(id, syncStore);
if (cb !== undefined) {
return cb(result);
}
Expand Down Expand Up @@ -325,7 +325,7 @@ var storage = {
},
local: {
get: jest.fn(function (id, cb) {
var result = id === null ? localStore : resolveKey(id, localStore);
var result = id === null || id === undefined ? localStore : resolveKey(id, localStore);
if (cb !== undefined) {
return cb(result);
}
Expand Down Expand Up @@ -367,7 +367,7 @@ var storage = {
},
managed: {
get: jest.fn(function (id, cb) {
var result = id === null ? managedStore : resolveKey(id, managedStore);
var result = id === null || id === undefined ? managedStore : resolveKey(id, managedStore);
if (cb !== undefined) {
return cb(result);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jest-webextension-mock",
"version": "3.8.15",
"version": "3.8.16",
"description": "Mock the components of a WebExtension",
"main": "dist/setup.js",
"module": "src/setup.js",
Expand Down
13 changes: 10 additions & 3 deletions src/storage.js
Expand Up @@ -26,7 +26,8 @@ function resolveKey(key, store) {
export const storage = {
sync: {
get: jest.fn((id, cb) => {
const result = id === null ? syncStore : resolveKey(id, syncStore);
const result =
id === null || id === undefined ? syncStore : resolveKey(id, syncStore);
if (cb !== undefined) {
return cb(result);
}
Expand Down Expand Up @@ -64,7 +65,10 @@ export const storage = {
},
local: {
get: jest.fn((id, cb) => {
const result = id === null ? localStore : resolveKey(id, localStore);
const result =
id === null || id === undefined
? localStore
: resolveKey(id, localStore);
if (cb !== undefined) {
return cb(result);
}
Expand Down Expand Up @@ -102,7 +106,10 @@ export const storage = {
},
managed: {
get: jest.fn((id, cb) => {
const result = id === null ? managedStore : resolveKey(id, managedStore);
const result =
id === null || id === undefined
? managedStore
: resolveKey(id, managedStore);
if (cb !== undefined) {
return cb(result);
}
Expand Down

0 comments on commit 03315a8

Please sign in to comment.