-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamelize.spec.ts
More file actions
50 lines (40 loc) · 1.67 KB
/
Copy pathcamelize.spec.ts
File metadata and controls
50 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { camelize } from './camelize';
describe('camelize', () => {
it('should convert space-separated words to camelCase', () => {
expect(camelize('first name')).toEqual('firstName');
expect(camelize('user profile id')).toEqual('userProfileId');
});
it('should convert hyphenated words to camelCase', () => {
expect(camelize('first-name')).toEqual('firstName');
expect(camelize('user-profile-id')).toEqual('userProfileId');
});
it('should convert snake_case to camelCase', () => {
expect(camelize('first_name')).toEqual('firstName');
expect(camelize('user_profile_id')).toEqual('userProfileId');
});
it('should handle mixed delimiters', () => {
expect(camelize('user-profile_id')).toEqual('userProfileId');
expect(camelize('user profile_id-name')).toEqual('userProfileIdName');
});
it('should lowercase the first character', () => {
expect(camelize('First Name')).toEqual('firstName');
});
it('should remove non-alphanumeric characters', () => {
expect(camelize('user@name!')).toEqual('userName');
expect(camelize('hello.world')).toEqual('helloWorld');
});
it('should handle numbers correctly', () => {
expect(camelize('version 2 id')).toEqual('version2Id');
expect(camelize('api_2_response')).toEqual('api2Response');
});
it('should return empty string for empty input', () => {
expect(camelize('')).toEqual('');
});
it('should not change already camelCased input', () => {
expect(camelize('alreadyCamelCase')).toEqual('alreadyCamelCase');
});
it('should handle a single word', () => {
expect(camelize('username')).toEqual('username');
expect(camelize('Username')).toEqual('username');
});
});