|
| 1 | +import { truncate } from '../Truncate.js' |
| 2 | + |
| 3 | +describe('truncate', () => { |
| 4 | + test("truncate('Hello World', 5) returns 'Hello...'", () => { |
| 5 | + expect(truncate('Hello World', 5)).toBe('Hello...') |
| 6 | + }) |
| 7 | + |
| 8 | + test("truncate('Hi', 5) returns 'Hi'", () => { |
| 9 | + expect(truncate('Hi', 5)).toBe('Hi') |
| 10 | + }) |
| 11 | + |
| 12 | + test('truncate at exact length returns original', () => { |
| 13 | + expect(truncate('Hello', 5)).toBe('Hello') |
| 14 | + }) |
| 15 | + |
| 16 | + test("truncate('Hello World', 11) returns 'Hello World'", () => { |
| 17 | + expect(truncate('Hello World', 11)).toBe('Hello World') |
| 18 | + }) |
| 19 | + |
| 20 | + test('truncate empty string returns empty string', () => { |
| 21 | + expect(truncate('', 5)).toBe('') |
| 22 | + }) |
| 23 | + |
| 24 | + test('truncate with maxLength 1', () => { |
| 25 | + expect(truncate('Hello', 1)).toBe('H...') |
| 26 | + }) |
| 27 | + |
| 28 | + test('truncate long string', () => { |
| 29 | + expect(truncate('The quick brown fox', 9)).toBe('The quick...') |
| 30 | + }) |
| 31 | + |
| 32 | + test('throws TypeError for non-string input', () => { |
| 33 | + expect(() => truncate(123, 5)).toThrow(TypeError) |
| 34 | + }) |
| 35 | + |
| 36 | + test('throws TypeError for zero maxLength', () => { |
| 37 | + expect(() => truncate('Hello', 0)).toThrow(TypeError) |
| 38 | + }) |
| 39 | + |
| 40 | + test('throws TypeError for negative maxLength', () => { |
| 41 | + expect(() => truncate('Hello', -1)).toThrow(TypeError) |
| 42 | + }) |
| 43 | + |
| 44 | + test('throws TypeError for float maxLength', () => { |
| 45 | + expect(() => truncate('Hello', 2.5)).toThrow(TypeError) |
| 46 | + }) |
| 47 | +}) |
0 commit comments