@pyreon/core 0.7.6 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ import { cx } from "../style"
2
+
3
+ describe("cx", () => {
4
+ test("returns empty string for falsy values", () => {
5
+ expect(cx(null)).toBe("")
6
+ expect(cx(undefined)).toBe("")
7
+ expect(cx(false)).toBe("")
8
+ expect(cx(true)).toBe("")
9
+ })
10
+
11
+ test("passes through strings", () => {
12
+ expect(cx("foo bar")).toBe("foo bar")
13
+ })
14
+
15
+ test("converts numbers to strings", () => {
16
+ expect(cx(42)).toBe("42")
17
+ })
18
+
19
+ test("filters and joins arrays", () => {
20
+ expect(cx(["foo", false, "bar", null, "baz"])).toBe("foo bar baz")
21
+ })
22
+
23
+ test("resolves object keys with truthy values", () => {
24
+ expect(cx({ active: true, hidden: false, bold: true })).toBe("active bold")
25
+ })
26
+
27
+ test("resolves object values that are functions", () => {
28
+ expect(cx({ active: () => true, hidden: () => false })).toBe("active")
29
+ })
30
+
31
+ test("handles nested arrays and objects", () => {
32
+ expect(cx(["base", { active: true }, ["nested", { deep: true }]])).toBe(
33
+ "base active nested deep",
34
+ )
35
+ })
36
+
37
+ test("handles empty inputs", () => {
38
+ expect(cx([])).toBe("")
39
+ expect(cx({})).toBe("")
40
+ })
41
+ })
@@ -0,0 +1,77 @@
1
+ import { createUniqueId, mergeProps, splitProps } from "../props"
2
+
3
+ describe("splitProps", () => {
4
+ test("splits known keys from rest", () => {
5
+ const props = { label: "Hi", icon: "star", class: "btn", id: "x" }
6
+ const [own, html] = splitProps(props, ["label", "icon"])
7
+ expect(own).toEqual({ label: "Hi", icon: "star" })
8
+ expect(html).toEqual({ class: "btn", id: "x" })
9
+ })
10
+
11
+ test("preserves getters", () => {
12
+ let count = 0
13
+ const props = Object.defineProperty({} as Record<string, unknown>, "value", {
14
+ get: () => ++count,
15
+ enumerable: true,
16
+ configurable: true,
17
+ })
18
+ const [own] = splitProps(props, ["value"])
19
+ expect(own.value).toBe(1)
20
+ expect(own.value).toBe(2) // getter called again
21
+ })
22
+
23
+ test("handles empty keys array", () => {
24
+ const props = { a: 1, b: 2 }
25
+ const [own, rest] = splitProps(props, [])
26
+ expect(own).toEqual({})
27
+ expect(rest).toEqual({ a: 1, b: 2 })
28
+ })
29
+ })
30
+
31
+ describe("mergeProps", () => {
32
+ test("later sources override earlier", () => {
33
+ const result = mergeProps({ a: 1, b: 2 }, { b: 3, c: 4 })
34
+ expect(result).toEqual({ a: 1, b: 3, c: 4 })
35
+ })
36
+
37
+ test("undefined values don't override defined", () => {
38
+ const result = mergeProps({ size: "md" }, { size: undefined as string | undefined })
39
+ expect(result.size).toBe("md")
40
+ })
41
+
42
+ test("preserves getters from sources", () => {
43
+ let count = 0
44
+ const source = Object.defineProperty({} as Record<string, unknown>, "val", {
45
+ get: () => ++count,
46
+ enumerable: true,
47
+ configurable: true,
48
+ })
49
+ const result = mergeProps({ val: 0 }, source)
50
+ expect(result.val).toBe(1)
51
+ expect(result.val).toBe(2)
52
+ })
53
+
54
+ test("getter returning undefined falls back to previous value", () => {
55
+ let override: string | undefined
56
+ const source = Object.defineProperty({} as Record<string, unknown>, "size", {
57
+ get: () => override,
58
+ enumerable: true,
59
+ configurable: true,
60
+ })
61
+ const result = mergeProps({ size: "md" }, source)
62
+ expect(result.size).toBe("md") // getter returns undefined, fallback
63
+
64
+ override = "lg"
65
+ expect(result.size).toBe("lg") // getter returns value
66
+ })
67
+ })
68
+
69
+ describe("createUniqueId", () => {
70
+ test("returns incrementing IDs", () => {
71
+ const id1 = createUniqueId()
72
+ const id2 = createUniqueId()
73
+ expect(id1).toMatch(/^pyreon-\d+$/)
74
+ expect(id2).toMatch(/^pyreon-\d+$/)
75
+ expect(id1).not.toBe(id2)
76
+ })
77
+ })