|
4 | 4 | import { Text } from '../Text'; |
5 | 5 |
|
6 | 6 | describe('Text', () => { |
7 | | - it('Text.padEnd()', () => { |
8 | | - expect(Text.padEnd('', 5)).toEqual( ' '); |
9 | | - expect(Text.padEnd('123', 5)).toEqual( '123 '); |
10 | | - expect(Text.padEnd('12345', 5)).toEqual( '12345'); |
11 | | - expect(Text.padEnd('123456', 5)).toEqual('123456'); |
| 7 | + describe('padEnd', () => { |
| 8 | + it('Throws an exception if the padding character isn\'t a single character', () => { |
| 9 | + expect(() => Text.padEnd('123', 1, '')).toThrow(); |
| 10 | + expect(() => Text.padEnd('123', 1, ' ')).toThrow(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('Doesn\'t change the string if it\'s already at or greater than the minimum length', () => { |
| 14 | + expect(Text.padEnd('12345', 5)).toEqual( '12345'); |
| 15 | + expect(Text.padEnd('123456', 5)).toEqual('123456'); |
| 16 | + expect(Text.padEnd('12345', 5, '0')).toEqual( '12345'); |
| 17 | + expect(Text.padEnd('123456', 5, '0')).toEqual('123456'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('Appends the default character (spaces) to the end of a string', () => { |
| 21 | + expect(Text.padEnd('', 5)).toEqual( ' '); |
| 22 | + expect(Text.padEnd('123', 5)).toEqual('123 '); |
| 23 | + }); |
| 24 | + |
| 25 | + it('Appends the characters to the end of a string', () => { |
| 26 | + expect(Text.padEnd('', 5, '0')).toEqual( '00000'); |
| 27 | + expect(Text.padEnd('123', 5, '0')).toEqual('12300'); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('padStart', () => { |
| 32 | + it('Throws an exception if the padding character isn\'t a single character', () => { |
| 33 | + expect(() => Text.padStart('123', 1, '')).toThrow(); |
| 34 | + expect(() => Text.padStart('123', 1, ' ')).toThrow(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('Doesn\'t change the string if it\'s already at or greater than the minimum length', () => { |
| 38 | + expect(Text.padStart('12345', 5)).toEqual( '12345'); |
| 39 | + expect(Text.padStart('123456', 5)).toEqual('123456'); |
| 40 | + expect(Text.padStart('12345', 5, '0')).toEqual( '12345'); |
| 41 | + expect(Text.padStart('123456', 5, '0')).toEqual('123456'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('Appends the default character (spaces) to the end of a string', () => { |
| 45 | + expect(Text.padStart('', 5)).toEqual( ' '); |
| 46 | + expect(Text.padStart('123', 5)).toEqual(' 123'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('Appends the characters to the end of a string', () => { |
| 50 | + expect(Text.padStart('', 5, '0')).toEqual( '00000'); |
| 51 | + expect(Text.padStart('123', 5, '0')).toEqual('00123'); |
| 52 | + }); |
12 | 53 | }); |
13 | | - it('Text.truncateWithEllipsis()', () => { |
14 | | - expect(() => { |
15 | | - Text.truncateWithEllipsis('123', -1); |
16 | | - }).toThrow(); |
17 | | - expect(Text.truncateWithEllipsis('123', 0)).toEqual( ''); |
18 | | - |
19 | | - expect(Text.truncateWithEllipsis('', 2)).toEqual( ''); |
20 | | - expect(Text.truncateWithEllipsis('1', 2)).toEqual( '1'); |
21 | | - expect(Text.truncateWithEllipsis('12', 2)).toEqual( '12'); |
22 | | - expect(Text.truncateWithEllipsis('123', 2)).toEqual( '12'); |
23 | | - |
24 | | - expect(Text.truncateWithEllipsis('123', 5)).toEqual( '123'); |
25 | | - expect(Text.truncateWithEllipsis('1234', 5)).toEqual( '1234'); |
26 | | - expect(Text.truncateWithEllipsis('12345', 5)).toEqual( '12345'); |
27 | | - expect(Text.truncateWithEllipsis('123456', 5)).toEqual('12...'); |
| 54 | + |
| 55 | + describe('truncateWithEllipsis', () => { |
| 56 | + it('Throws an exception if the maximum length is less than zero', () => { |
| 57 | + expect(() => Text.truncateWithEllipsis('123', -1)).toThrow(); |
| 58 | + }); |
| 59 | + |
| 60 | + it('Doesn\'t change the string if it\'s already shorter than the maximum length', () => { |
| 61 | + expect(Text.truncateWithEllipsis('', 2)).toEqual( ''); |
| 62 | + expect(Text.truncateWithEllipsis('1', 2)).toEqual( '1'); |
| 63 | + expect(Text.truncateWithEllipsis('12', 2)).toEqual( '12'); |
| 64 | + |
| 65 | + expect(Text.truncateWithEllipsis('123', 5)).toEqual( '123'); |
| 66 | + expect(Text.truncateWithEllipsis('1234', 5)).toEqual( '1234'); |
| 67 | + }); |
| 68 | + |
| 69 | + it('Truncates strings', () => { |
| 70 | + expect(Text.truncateWithEllipsis('123', 0)).toEqual( ''); |
| 71 | + expect(Text.truncateWithEllipsis('123', 2)).toEqual( '12'); |
| 72 | + expect(Text.truncateWithEllipsis('12345', 5)).toEqual( '12345'); |
| 73 | + expect(Text.truncateWithEllipsis('123456', 5)).toEqual('12...'); |
| 74 | + }); |
28 | 75 | }); |
29 | 76 | }); |
0 commit comments