Skip to content

Commit

Permalink
fix(prefixStorage): wrap shorthand aliases (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinTh authored Dec 30, 2024
1 parent 990e776 commit 5af560b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import type { Storage, StorageValue } from "./types";
type StorageKeys = Array<keyof Storage>;

const storageKeyProperties: StorageKeys = [
"has",
"hasItem",
"get",
"getItem",
"getItemRaw",
"set",
"setItem",
"setItemRaw",
"del",
"remove",
"removeItem",
"getMeta",
"setMeta",
Expand Down
19 changes: 19 additions & 0 deletions test/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,23 @@ describe("Regression", () => {
expect(setItem).toHaveBeenCalledTimes(0);
expect(setItems).toHaveBeenCalledTimes(1);
});

it("prefixed storage supports aliases", async () => {
const storage = createStorage();
const pStorage = prefixStorage(storage, "foo");

await pStorage.set("x", "foo");
await pStorage.set("y", "bar");

expect(await pStorage.get("x")).toBe("foo");
expect(await pStorage.get("x")).toBe("foo");
expect(await pStorage.has("x")).toBe(true);
expect(await pStorage.get("y")).toBe("bar");

await pStorage.del("x");
expect(await pStorage.has("x")).toBe(false);

await pStorage.remove("y");
expect(await pStorage.has("y")).toBe(false);
});
});

0 comments on commit 5af560b

Please sign in to comment.