Files
pepperplus-ui/test/utils/capitalize.test.ts
2026-01-28 10:15:58 +00:00

35 lines
1.0 KiB
TypeScript

import capitalize from "../../src/utils/capitalize.ts";
describe('capitalize', () => {
it('capitalizes the first letter of a lowercase word', () => {
expect(capitalize('hello')).toBe('Hello');
});
it('keeps the first letter capitalized if already uppercase', () => {
expect(capitalize('Hello')).toBe('Hello');
});
it('handles single character strings', () => {
expect(capitalize('a')).toBe('A');
expect(capitalize('A')).toBe('A');
});
it('returns empty string for empty input', () => {
expect(capitalize('')).toBe('');
});
it('only capitalizes the first letter, leaving the rest unchanged', () => {
expect(capitalize('hELLO')).toBe('HELLO');
expect(capitalize('hello world')).toBe('Hello world');
});
it('handles strings starting with numbers', () => {
expect(capitalize('123abc')).toBe('123abc');
});
it('handles strings starting with special characters', () => {
expect(capitalize('!hello')).toBe('!hello');
expect(capitalize(' hello')).toBe(' hello');
});
});