Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { test, describe } from 'node:test';
import assert from 'node:assert/strict';
import { cn } from '../lib/utils';

describe('cn utility function', () => {
test('combines basic classes correctly', () => {
assert.equal(cn('a', 'b', 'c'), 'a b c');
});

test('handles conditional classes', () => {
const condition = true;
const falseCondition = false;
assert.equal(cn('a', condition && 'b', falseCondition && 'c'), 'a b');
});

test('handles array inputs', () => {
assert.equal(cn(['a', 'b'], ['c', 'd']), 'a b c d');
});

test('handles object inputs', () => {
assert.equal(cn({ a: true, b: false, c: true }), 'a c');
});

test('handles mixed inputs (string, array, object)', () => {
assert.equal(
cn('a', ['b', 'c'], { d: true, e: false }, 'f'),
'a b c d f'
);
});

test('merges tailwind classes correctly (twMerge)', () => {
// p-4 and p-8 are conflicting padding classes, twMerge should keep the last one
assert.equal(cn('p-4', 'p-8'), 'p-8');

// text-red-500 and text-blue-500 are conflicting text color classes
assert.equal(cn('text-red-500', 'text-blue-500'), 'text-blue-500');

// bg-red-500 and hover:bg-blue-500 do not conflict directly but are related
assert.equal(
cn('bg-red-500 hover:bg-blue-500', 'bg-blue-500'),
'hover:bg-blue-500 bg-blue-500'
);
});

test('handles falsy values', () => {
assert.equal(cn('a', null, undefined, false, 0, '', 'b'), 'a b');
});

test('handles empty input', () => {
assert.equal(cn(), '');
});
});
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint"
"lint": "eslint",
"test": "tsx --test __tests__/**/*.test.ts"
},
"dependencies": {
"@ai-sdk/google": "^3.0.53",
Expand Down Expand Up @@ -77,6 +78,7 @@
"serwist": "^9.5.7",
"shadcn": "^3.8.4",
"tailwindcss": "^4",
"tsx": "^4.21.0",
"tw-animate-css": "^1.4.0",
"typescript": "5.7.3"
}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"allowImportingTsExtensions": true,
"plugins": [
{
"name": "next"
Expand Down