Skip to content

Commit d3902e2

Browse files
committed
Full test coverage
1 parent 3ece85a commit d3902e2

File tree

6 files changed

+904
-70
lines changed

6 files changed

+904
-70
lines changed

packages/onchainkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"format": "prettier --write .",
1717
"typecheck": "tsc --noEmit",
1818
"test": "vitest run",
19-
"test:coverage": "vitest run --coverage",
19+
"test:coverage": "vitest run --coverage --coverage.all=false",
2020
"test:watch": "vitest",
2121
"test:ui": "vitest --ui",
2222
"get-next-version": "node ./scripts/get-next-version.js",

packages/onchainkit/plugins/__tests__/babel-prefix-react-classnames.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,58 @@ describe('babel-prefix-react-classnames', () => {
310310
});
311311
expect(result).not.toContain('className');
312312
});
313+
314+
it('should add universal class to template literal className on HTML elements', () => {
315+
const code = '<div className={`foo ${bar}`}>Hello</div>';
316+
const result = transform(code, {
317+
prefix: 'prefix-',
318+
universalClass: 'el',
319+
});
320+
expect(result).toContain('prefix-el');
321+
expect(result).toContain('prefix-foo');
322+
});
323+
324+
it('should add universal class to HTML elements without className', () => {
325+
const code = '<div>Hello</div>';
326+
const result = transform(code, {
327+
prefix: 'prefix-',
328+
universalClass: 'el',
329+
});
330+
expect(result).toContain('className: "prefix-el"');
331+
});
332+
333+
it('should not add universal class if no universalClass option is set', () => {
334+
const code = '<div>Hello</div>';
335+
const result = transform(code, {
336+
prefix: 'prefix-',
337+
});
338+
expect(result).not.toContain('className');
339+
});
340+
341+
it('should handle React components without adding universal class', () => {
342+
const code = '<Button className="foo">Click</Button>';
343+
const result = transform(code, {
344+
prefix: 'prefix-',
345+
universalClass: 'el',
346+
});
347+
// React component should get prefix but not universal class
348+
expect(result).toContain('prefix-foo');
349+
expect(result).not.toContain('prefix-el');
350+
});
351+
352+
it('should handle multiple HTML elements with and without className', () => {
353+
const code = `
354+
<div>
355+
<span className="text">Hello</span>
356+
<button>Click</button>
357+
</div>
358+
`;
359+
const result = transform(code, {
360+
prefix: 'prefix-',
361+
universalClass: 'el',
362+
});
363+
// All HTML elements should get universal class
364+
expect(result.match(/prefix-el/g)?.length).toBeGreaterThanOrEqual(3);
365+
});
313366
});
314367
});

0 commit comments

Comments
 (0)