Files
portfolio/src/shared/lib/cn.test.ts
T

40 lines
994 B
TypeScript
Raw Normal View History

import { cn } from './cn';
2026-04-18 15:49:24 +03:00
describe('cn', () => {
describe('basic merging', () => {
it('returns single class unchanged', () => {
expect(cn('foo')).toBe('foo');
});
2026-04-18 15:49:24 +03:00
it('joins multiple classes', () => {
expect(cn('foo', 'bar')).toBe('foo bar');
});
});
2026-04-18 15:49:24 +03:00
describe('conditional classes', () => {
it('includes truthy conditional', () => {
expect(cn('foo', true && 'bar')).toBe('foo bar');
});
2026-04-18 15:49:24 +03:00
it('excludes falsy conditional', () => {
expect(cn('foo', false && 'bar')).toBe('foo');
});
});
2026-04-18 15:49:24 +03:00
describe('object syntax', () => {
it('includes classes with truthy object values', () => {
expect(cn({ foo: true, bar: false })).toBe('foo');
});
});
2026-04-18 15:49:24 +03:00
describe('tailwind conflict resolution', () => {
it('last padding wins', () => {
expect(cn('px-2', 'px-4')).toBe('px-4');
});
2026-04-18 15:49:24 +03:00
it('last text color wins', () => {
expect(cn('text-red-500', 'text-blue-500')).toBe('text-blue-500');
});
});
});