Skip to content

Commit f9df8fc

Browse files
authored
Merge pull request #3 from morishxt/add-unit-tests
Add 4 missing unit tests
2 parents b09d1a2 + 1a9a0a0 commit f9df8fc

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@
3434
],
3535
"repository": {
3636
"type": "git",
37-
"url": "https://github.com/morishxt/windctrl.git"
37+
"url": "git+https://github.com/morishxt/windctrl.git"
3838
},
3939
"bugs": {
4040
"url": "https://github.com/morishxt/windctrl/issues"
4141
},
4242
"homepage": "https://github.com/morishxt/windctrl#readme",
4343
"scripts": {
4444
"test": "vitest",
45-
"test:watch": "vitest --watch",
46-
"test:coverage": "vitest --coverage",
4745
"build": "tsc",
4846
"dev": "tsc --watch",
4947
"format": "prettier --write .",

src/index.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,19 @@ describe("windctrl", () => {
306306
const numberResult = button({ w: 300 });
307307
expect(numberResult.style).toEqual({ width: "300px" });
308308
});
309+
310+
it("should resolve style conflicts with last one wins for dynamic styles", () => {
311+
const box = windctrl({
312+
dynamic: {
313+
w1: () => ({ style: { width: "100px" } }),
314+
w2: () => ({ style: { width: "200px" } }),
315+
},
316+
});
317+
318+
const result = box({ w1: true as any, w2: true as any });
319+
320+
expect(result.style).toEqual({ width: "200px" });
321+
});
309322
});
310323

311324
describe("Scopes", () => {
@@ -342,6 +355,23 @@ describe("windctrl", () => {
342355
"group-data-[scope=header]/wind-scope:text-sm",
343356
);
344357
});
358+
359+
it("should prefix every scope class when multiple classes are provided", () => {
360+
const button = windctrl({
361+
scopes: {
362+
header: "text-sm py-1",
363+
},
364+
});
365+
366+
const result = button({});
367+
368+
expect(result.className).toContain(
369+
"group-data-[scope=header]/wind-scope:text-sm",
370+
);
371+
expect(result.className).toContain(
372+
"group-data-[scope=header]/wind-scope:py-1",
373+
);
374+
});
345375
});
346376

347377
describe("Priority and Integration", () => {
@@ -446,6 +476,34 @@ describe("windctrl", () => {
446476
expect(result.className).toContain("text-blue-500");
447477
expect(result.className).not.toContain("text-red-500");
448478
});
479+
480+
it("should let Dynamic override Traits when Tailwind classes conflict (via twMerge)", () => {
481+
const button = windctrl({
482+
traits: {
483+
padded: "p-2",
484+
},
485+
dynamic: {
486+
p: (val) => (typeof val === "number" ? `p-${val}` : val),
487+
},
488+
});
489+
490+
const result = button({ traits: ["padded"], p: 4 });
491+
492+
expect(result.className).toContain("p-4");
493+
expect(result.className).not.toContain("p-2");
494+
});
495+
496+
it("should let Traits override Base when Tailwind classes conflict (via twMerge)", () => {
497+
const button = windctrl({
498+
base: "p-1",
499+
traits: { padded: "p-3" },
500+
});
501+
502+
const result = button({ traits: ["padded"] });
503+
504+
expect(result.className).toContain("p-3");
505+
expect(result.className).not.toContain("p-1");
506+
});
449507
});
450508

451509
describe("Edge cases", () => {

0 commit comments

Comments
 (0)