Reintroduce null object remove rerouting (#8920)

* Reintroduce null object remove rerouting

* Test remove redirect

(cherry picked from commit e516eec200)
This commit is contained in:
Matt Gibson 2024-04-25 14:55:45 -04:00
parent f9b334db8b
commit 4e9363538f
No known key found for this signature in database
GPG Key ID: 963EE038B0581878
2 changed files with 16 additions and 0 deletions

View File

@ -78,6 +78,11 @@ export default abstract class AbstractChromeStorageService
async save(key: string, obj: any): Promise<void> {
obj = objToStore(obj);
if (obj == null) {
// Safari does not support set of null values
return this.remove(key);
}
const keyedObj = { [key]: obj };
return new Promise<void>((resolve) => {
this.chromeStorageApi.set(keyedObj, () => {

View File

@ -62,6 +62,17 @@ describe("ChromeStorageApiService", () => {
expect.any(Function),
);
});
it("removes the key when the value is null", async () => {
const removeMock = chrome.storage.local.remove as jest.Mock;
removeMock.mockImplementation((key, callback) => {
delete store[key];
callback();
});
const key = "key";
await service.save(key, null);
expect(removeMock).toHaveBeenCalledWith(key, expect.any(Function));
});
});
describe("get", () => {