78532bc7bb
Co-authored-by: Dennis Simon <dennism.simon94@gmail.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { it } from 'vitest';
|
|
import { useTruncateMiddle } from './useTruncateMiddle';
|
|
|
|
describe('useTruncateMiddle', () => {
|
|
it('returns original text when maxLength is less than 3', () => {
|
|
const result = useTruncateMiddle({ text: 'Hello, World!', maxLength: 2 });
|
|
expect(result).toBe('Hello, World!');
|
|
});
|
|
|
|
it('returns original text when text length is less than or equal to maxLength', () => {
|
|
const result = useTruncateMiddle({ text: 'Hello, World!', maxLength: 13 });
|
|
expect(result).toBe('Hello, World!');
|
|
});
|
|
|
|
it('truncates text with even maxLength correctly', () => {
|
|
const result = useTruncateMiddle({ text: 'Hello, World!', maxLength: 10 });
|
|
expect(result).toBe('Hell…orld!');
|
|
});
|
|
|
|
it('truncates text with odd maxLength correctly', () => {
|
|
const result = useTruncateMiddle({ text: 'Hello, World!', maxLength: 9 });
|
|
expect(result).toBe('Hell…rld!');
|
|
});
|
|
|
|
it('returns original text when text is empty', () => {
|
|
const result = useTruncateMiddle({ text: '', maxLength: 10 });
|
|
expect(result).toBe('');
|
|
});
|
|
}); |