Package library as @moduletrace/twui npm package
- Move components/ to src/ and compile to dist/ with tsc - Add root barrel export plus deep-import subpath exports and base.css export - Post-compile step: copy base.css, add .js import extensions, mark client modules - Add publish.sh and .npmrc for the Gitea npm registry - Fix type errors, guard TinyMCE env access, drop ace-builds type dependency - Rename clashing props type names, remove Next.js scaffolding and unused deps Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import twuiSerializeQuery from "./serialize-query";
|
||||
|
||||
describe("twuiSerializeQuery", () => {
|
||||
test("returns '?' for non-object input", () => {
|
||||
expect(twuiSerializeQuery("string" as any)).toBe("?");
|
||||
});
|
||||
|
||||
test("returns '?' for array input", () => {
|
||||
expect(twuiSerializeQuery([1, 2] as any)).toBe("?");
|
||||
});
|
||||
|
||||
test("returns '?' for null input", () => {
|
||||
expect(twuiSerializeQuery(null as any)).toBe("?");
|
||||
});
|
||||
|
||||
test("serializes simple object", () => {
|
||||
const result = twuiSerializeQuery({ foo: "bar" });
|
||||
expect(result).toBe("?foo=bar");
|
||||
});
|
||||
|
||||
test("serializes multiple keys", () => {
|
||||
const result = twuiSerializeQuery({ a: "1", b: "2" });
|
||||
expect(result).toContain("a=1");
|
||||
expect(result).toContain("b=2");
|
||||
});
|
||||
|
||||
test("serializes numeric value", () => {
|
||||
const result = twuiSerializeQuery({ page: 2 });
|
||||
expect(result).toContain("page=2");
|
||||
});
|
||||
|
||||
test("skips empty key", () => {
|
||||
const result = twuiSerializeQuery({ "": "value", foo: "bar" });
|
||||
expect(result).not.toContain("=value");
|
||||
expect(result).toContain("foo=bar");
|
||||
});
|
||||
|
||||
test("skips falsy value", () => {
|
||||
const result = twuiSerializeQuery({ empty: "", foo: "bar" });
|
||||
expect(result).not.toContain("empty=");
|
||||
expect(result).toContain("foo=bar");
|
||||
});
|
||||
|
||||
test("JSON-encodes object values", () => {
|
||||
const result = twuiSerializeQuery({ filter: { field: "name" } });
|
||||
expect(result).toContain("filter=");
|
||||
expect(result).toContain("field");
|
||||
});
|
||||
|
||||
test("URL-encodes values", () => {
|
||||
const result = twuiSerializeQuery({ q: "hello world" });
|
||||
expect(result).toContain("q=hello%20world");
|
||||
});
|
||||
|
||||
test("serializes boolean value as string", () => {
|
||||
const result = twuiSerializeQuery({ active: true as any });
|
||||
expect(result).toContain("active=true");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user