Repository navigation
Expand file tree
/
Copy pathstring.test.ts
More file actions
39 lines (32 loc) · 1.6 KB
/
Copy pathstring.test.ts
File metadata and controls
39 lines (32 loc) · 1.6 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
import { keysToEventMessage, truncate } from '../src/string';
describe('truncate()', () => {
test('it works as expected', () => {
expect(truncate('lolol', 3)).toEqual('lol...');
expect(truncate('lolol', 10)).toEqual('lolol');
expect(truncate('1'.repeat(1000), 300)).toHaveLength(303);
expect(truncate(new Array(1000).join('f'), 0)).toEqual(new Array(1000).join('f'));
expect(truncate(new Array(1000).join('f'), 0)).toEqual(new Array(1000).join('f'));
});
});
describe('keysToEventMessage()', () => {
test('no keys', () => {
expect(keysToEventMessage([], 10)).toEqual('[object has no keys]');
});
test('one key should be returned as a whole if not over the length limit', () => {
expect(keysToEventMessage(['foo'], 10)).toEqual('foo');
expect(keysToEventMessage(['foobarbazx'], 10)).toEqual('foobarbazx');
});
test('one key should be appended with ... and truncated when over the limit', () => {
expect(keysToEventMessage(['foobarbazqux'], 10)).toEqual('foobarbazq...');
});
test('multiple keys should be joined as a whole if not over the length limit', () => {
expect(keysToEventMessage(['foo', 'bar'], 10)).toEqual('foo, bar');
});
test('multiple keys should include only as much keys as can fit into the limit', () => {
expect(keysToEventMessage(['foo', 'bar', 'baz'], 10)).toEqual('foo, bar');
expect(keysToEventMessage(['foo', 'verylongkey', 'baz'], 10)).toEqual('foo');
});
test('multiple keys should truncate first key if its too long', () => {
expect(keysToEventMessage(['foobarbazqux', 'bar', 'baz'], 10)).toEqual('foobarbazq...');
});
});