Files
jinshen-website/app/utils/file.test.ts
R2m1liA d7bd034d7d
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m5s
test: 优化测试代码
- 显式导入相关依赖以避免相关问题
2025-11-14 12:23:49 +08:00

48 lines
1.3 KiB
TypeScript

import { expect, test, describe } from 'vitest';
import { formatFileSize, getFileExtension, formatFileExtension } from './file';
/**
* 单元测试: formatFileSize
*/
describe('formatFileSize', () => {
test('format bytes correctly', () => {
expect(formatFileSize(500)).toBe('500.00 B');
});
test('format kilobytes correctly', () => {
expect(formatFileSize(2048)).toBe('2.00 KB');
});
test('format megabytes correctly', () => {
expect(formatFileSize(5 * 1024 * 1024)).toBe('5.00 MB');
});
});
/**
* 单元测试: getFileExtension
*/
describe('getFileExtension', () => {
test('extract extension from filename', () => {
expect(getFileExtension('document.pdf')).toBe('pdf');
});
test('handle filenames without extension', () => {
expect(getFileExtension('README')).toBe('');
});
test('handle multiple dots in filename', () => {
expect(getFileExtension('archive.tar.gz')).toBe('gz');
});
test('handle empty filename', () => {
expect(getFileExtension('')).toBe('');
});
});
/**
* 单元测试: formatFileExtension
*/
describe('formatFileExtension', () => {
test('format extension without dot', () => {
expect(formatFileExtension('txt')).toBe('TXT');
});
test('format extension with dot', () => {
expect(formatFileExtension('.jpg')).toBe('JPG');
});
});