Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prefixStorage): wrap shorthand aliases #556

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading