-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathcount.js
More file actions
34 lines (30 loc) · 987 Bytes
/
count.js
File metadata and controls
34 lines (30 loc) · 987 Bytes
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
import { PRINTABLE_ASCII } from '../const';
import v from '../voca';
describe('count', function() {
it('should return the number of characters in a string', function() {
expect(v.count('rain')).toBe(4);
expect(v.count('')).toBe(0);
expect(v.count('rainbow')).toBe(7);
expect(v.count(PRINTABLE_ASCII)).toBe(PRINTABLE_ASCII.length);
});
it('should return the number of characters in a number', function() {
expect(v.count(123)).toBe(3);
expect(v.count(0)).toBe(1);
expect(v.count(-1.5)).toBe(4);
});
it('should return the number of characters in a string representation of an object', function() {
expect(v.count(['droplet'])).toBe(7);
expect(
v.count({
toString: function() {
return 'rainfall';
},
})
).toBe(8);
});
it('should return zero for undefined or null', function() {
expect(v.count()).toBe(0);
expect(v.count(null)).toBe(0);
expect(v.count(undefined)).toBe(0);
});
});