classnames.spec.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import cn from './classnames'
  2. describe('classnames', () => {
  3. test('classnames libs feature', () => {
  4. expect(cn('foo')).toBe('foo')
  5. expect(cn('foo', 'bar')).toBe('foo bar')
  6. expect(cn(['foo', 'bar'])).toBe('foo bar')
  7. expect(cn(undefined)).toBe('')
  8. expect(cn(null)).toBe('')
  9. expect(cn(false)).toBe('')
  10. expect(cn({
  11. foo: true,
  12. bar: false,
  13. baz: true,
  14. })).toBe('foo baz')
  15. })
  16. test('tailwind-merge', () => {
  17. expect(cn('p-0')).toBe('p-0')
  18. expect(cn('text-right text-center text-left')).toBe('text-left')
  19. expect(cn('pl-4 p-8')).toBe('p-8')
  20. expect(cn('m-[2px] m-[4px]')).toBe('m-[4px]')
  21. expect(cn('m-1 m-[4px]')).toBe('m-[4px]')
  22. expect(cn('overflow-x-auto hover:overflow-x-hidden overflow-x-scroll')).toBe(
  23. 'hover:overflow-x-hidden overflow-x-scroll',
  24. )
  25. expect(cn('h-10 h-min')).toBe('h-min')
  26. expect(cn('bg-grey-5 bg-hotpink')).toBe('bg-hotpink')
  27. expect(cn('hover:block hover:inline')).toBe('hover:inline')
  28. expect(cn('font-medium !font-bold')).toBe('font-medium !font-bold')
  29. expect(cn('!font-medium !font-bold')).toBe('!font-bold')
  30. expect(cn('text-gray-100 text-primary-200')).toBe('text-primary-200')
  31. expect(cn('text-some-unknown-color text-components-input-bg-disabled text-primary-200')).toBe('text-primary-200')
  32. expect(cn('bg-some-unknown-color bg-components-input-bg-disabled bg-primary-200')).toBe('bg-primary-200')
  33. expect(cn('border-t border-white/10')).toBe('border-t border-white/10')
  34. expect(cn('border-t border-white')).toBe('border-t border-white')
  35. expect(cn('text-3.5xl text-black')).toBe('text-3.5xl text-black')
  36. })
  37. test('classnames combined with tailwind-merge', () => {
  38. expect(cn('text-right', {
  39. 'text-center': true,
  40. })).toBe('text-center')
  41. expect(cn('text-right', {
  42. 'text-center': false,
  43. })).toBe('text-right')
  44. })
  45. })