Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.0 KB
Raw Blame
// @vitest-environment happy-dom

import { beforeEach, describe, expect, it } from "vitest";
import { safeLocalStorageGet, safeLocalStorageKeys, safeLocalStorageRemove, safeLocalStorageSet } from "@/lib/backend/safeStorage";

describe("safeStorage", () => {
  beforeEach(() => {
    localStorage.clear();
  });

  it("gets, sets, and removes values safely", () => {
    expect(safeLocalStorageGet("test-key")).toBeNull();
    expect(safeLocalStorageSet("test-key", "hello")).toBe(true);
    expect(safeLocalStorageGet("test-key")).toBe("hello");

    safeLocalStorageRemove("test-key");
    expect(safeLocalStorageGet("test-key")).toBeNull();
  });

  it("lists all keys via safeLocalStorageKeys", () => {
    expect(safeLocalStorageKeys()).toEqual([]);

    safeLocalStorageSet("k1", "v1");
    safeLocalStorageSet("k2", "v2");
    safeLocalStorageSet("k3", "v3");

    const keys = safeLocalStorageKeys();
    expect(keys).toHaveLength(3);
    expect(keys).toContain("k1");
    expect(keys).toContain("k2");
    expect(keys).toContain("k3");
  });
});