|
| 1 | +import { describe, it, expect } from 'vitest' |
| 2 | +import useCamelize from '~/composables/useCamelize' |
| 3 | + |
| 4 | +describe('useCamelize', () => { |
| 5 | + const { camelize, toPascalCase, capitalizeFirstLetter } = useCamelize() |
| 6 | + |
| 7 | + describe('toPascalCase', () => { |
| 8 | + it('should convert dash-separated string to PascalCase', () => { |
| 9 | + expect(toPascalCase('hello-world')).toBe('HelloWorld') |
| 10 | + expect(toPascalCase('my-component-name')).toBe('MyComponentName') |
| 11 | + expect(toPascalCase('test-case')).toBe('TestCase') |
| 12 | + }) |
| 13 | + |
| 14 | + it('should handle single words', () => { |
| 15 | + expect(toPascalCase('hello')).toBe('Hello') |
| 16 | + expect(toPascalCase('test')).toBe('Test') |
| 17 | + }) |
| 18 | + |
| 19 | + it('should handle multiple consecutive dashes', () => { |
| 20 | + expect(toPascalCase('hello--world')).toBe('HelloWorld') |
| 21 | + expect(toPascalCase('test---case')).toBe('TestCase') |
| 22 | + }) |
| 23 | + |
| 24 | + it('should handle leading and trailing dashes', () => { |
| 25 | + expect(toPascalCase('-hello-world')).toBe('HelloWorld') |
| 26 | + expect(toPascalCase('hello-world-')).toBe('HelloWorld') |
| 27 | + expect(toPascalCase('-hello-world-')).toBe('HelloWorld') |
| 28 | + }) |
| 29 | + |
| 30 | + it('should handle edge cases', () => { |
| 31 | + expect(toPascalCase('')).toBe('') |
| 32 | + expect(toPascalCase('-')).toBe('') |
| 33 | + expect(toPascalCase('--')).toBe('') |
| 34 | + }) |
| 35 | + |
| 36 | + it('should handle non-string inputs gracefully', () => { |
| 37 | + // @ts-expect-error Testing runtime behavior |
| 38 | + expect(toPascalCase(null)).toBe('') |
| 39 | + // @ts-expect-error Testing runtime behavior |
| 40 | + expect(toPascalCase(undefined)).toBe('') |
| 41 | + // @ts-expect-error Testing runtime behavior |
| 42 | + expect(toPascalCase(123)).toBe('') |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + describe('capitalizeFirstLetter', () => { |
| 47 | + it('should capitalize first letter of a word', () => { |
| 48 | + expect(capitalizeFirstLetter('hello')).toBe('Hello') |
| 49 | + expect(capitalizeFirstLetter('world')).toBe('World') |
| 50 | + expect(capitalizeFirstLetter('test')).toBe('Test') |
| 51 | + }) |
| 52 | + |
| 53 | + it('should handle single character', () => { |
| 54 | + expect(capitalizeFirstLetter('a')).toBe('A') |
| 55 | + expect(capitalizeFirstLetter('z')).toBe('Z') |
| 56 | + }) |
| 57 | + |
| 58 | + it('should handle empty string', () => { |
| 59 | + expect(capitalizeFirstLetter('')).toBe('') |
| 60 | + }) |
| 61 | + |
| 62 | + it('should preserve rest of the word', () => { |
| 63 | + expect(capitalizeFirstLetter('helloWORLD')).toBe('HelloWORLD') |
| 64 | + expect(capitalizeFirstLetter('tEST')).toBe('TEST') |
| 65 | + }) |
| 66 | + }) |
| 67 | + |
| 68 | + describe('camelize (backward compatibility)', () => { |
| 69 | + it('should work the same as toPascalCase', () => { |
| 70 | + expect(camelize('hello-world')).toBe('HelloWorld') |
| 71 | + expect(camelize('my-component-name')).toBe('MyComponentName') |
| 72 | + expect(camelize).toBe(toPascalCase) |
| 73 | + }) |
| 74 | + }) |
| 75 | +}) |
0 commit comments