-
Notifications
You must be signed in to change notification settings - Fork 194
/
formatting.test.ts
45 lines (38 loc) 路 1.41 KB
/
formatting.test.ts
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
import { normalizeToKebabOrSnakeCase } from '../../src/utils';
describe('normalizeToKebabOrSnakeCase', () => {
it('should convert camelCase to kebab-case', () => {
const input = 'camelCaseString';
const output = normalizeToKebabOrSnakeCase(input);
expect(output).toBe('camel-case-string');
});
it('should replace spaces with dashes', () => {
const input = 'string with spaces';
const output = normalizeToKebabOrSnakeCase(input);
expect(output).toBe('string-with-spaces');
});
it('should keep underscores', () => {
const input = 'string_with_underscores';
const output = normalizeToKebabOrSnakeCase(input);
expect(output).toBe('string_with_underscores');
});
it('should handle empty string', () => {
const input = '';
const output = normalizeToKebabOrSnakeCase(input);
expect(output).toBe('');
});
it('should handle strings with leading/trailing spaces', () => {
const input = ' leading and trailing spaces ';
const output = normalizeToKebabOrSnakeCase(input);
expect(output).toBe('leading-and-trailing-spaces');
});
it('should handle nil value', () => {
const input = null;
const output = normalizeToKebabOrSnakeCase(input);
expect(output).toBe(undefined);
});
it('should handle undefined value', () => {
const input = undefined;
const output = normalizeToKebabOrSnakeCase(input);
expect(output).toBe(undefined);
});
});