-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathcapitalize.js
More file actions
51 lines (46 loc) · 1.75 KB
/
capitalize.js
File metadata and controls
51 lines (46 loc) · 1.75 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
51
import { PRINTABLE_ASCII } from '../const';
import v from '../voca';
describe('capitalize', function() {
it('should capitalize the first character in a string', function() {
expect(v.capitalize('APPLE')).toBe('APPLE');
expect(v.capitalize('apple')).toBe('Apple');
expect(v.capitalize('macBook')).toBe('MacBook');
expect(v.capitalize('f')).toBe('F');
expect(v.capitalize('')).toBe('');
expect(v.capitalize('*apple')).toBe('*apple');
expect(v.capitalize(PRINTABLE_ASCII)).toBe(PRINTABLE_ASCII);
});
it('should capitalize the first character in a string and keep the rest unmodified', function() {
expect(v.capitalize('apple', true)).toBe('Apple');
expect(v.capitalize('APPLE', true)).toBe('Apple');
expect(v.capitalize('яблоко', true)).toBe('Яблоко');
expect(v.capitalize('f', true)).toBe('F');
expect(v.capitalize('', true)).toBe('');
expect(v.capitalize('100', true)).toBe('100');
expect(v.capitalize(' ', true)).toBe(' ');
});
it('should capitalize the first character in a string representation of an object', function() {
expect(v.capitalize(['grape'])).toBe('Grape');
expect(
v.capitalize(
{
toString: function() {
return 'oRaNgE';
},
},
false
)
).toBe('ORaNgE');
});
it('should not modify numbers', function() {
expect(v.capitalize(100)).toBe('100');
expect(v.capitalize(812, false)).toBe('812');
});
it('should return an empty string for null or undefined', function() {
expect(v.capitalize()).toBe('');
expect(v.capitalize(undefined)).toBe('');
expect(v.capitalize(null)).toBe('');
expect(v.capitalize(undefined, true)).toBe('');
expect(v.capitalize(undefined, false)).toBe('');
});
});