1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01:00

Reintroduce null object remove rerouting (#8920)

* Reintroduce null object remove rerouting

* Test remove redirect
This commit is contained in:
Matt Gibson 2024-04-25 14:55:45 -04:00 committed by GitHub
parent 1e4158fd87
commit e516eec200
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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", () => {