Files
RSSHub/lib/utils/common-utils.test.ts
Tony 0410bd5f19 refactor(utils/time): use Temporal API (#23931)
* refactor(utils): use Temporal API

* refactor(route): migrate to @/utils/time

* fix(route/rfi): use Temporal for duration

* style: add oxlint rule for temporal

* fix: merge duplicated parse duration

* fix: remove duplicated convertDateToISO8601

* fix: remove outdated check

* fix: remove fake date
2026-11-19 05:47:25 +08:00

28 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { collapseWhitespace, getLocalhostAddress, getSubPath, toTitleCase } from '@/utils/common-utils';
describe('common-utils', () => {
it('toTitleCase', () => {
expect(toTitleCase('RSSHub IS AS aweSOme aS henry')).toBe('Rsshub Is as Awesome as Henry');
});
it('collapseWhitespace', () => {
expect(collapseWhitespace('')).toBe('');
expect(collapseWhitespace(null)).toBe(null);
expect(collapseWhitespace(undefined)).toBe(undefined);
expect(collapseWhitespace(' \n\n\n ')).toBe('');
expect(collapseWhitespace('a string already collapsed')).toBe('a string already collapsed');
expect(collapseWhitespace(' \n a lot of whitespaces and \n\n\n\n linebreaks \n\n ')).toBe('a lot of whitespaces and linebreaks');
});
it('getLocalhostAddress', () => {
expect(getLocalhostAddress()).toBeInstanceOf(Array);
});
it('getSubPath', () => {
expect(getSubPath({ req: { path: '/test/abc' } })).toBe('/abc');
expect(getSubPath({ req: { path: '/test' } })).toBe('/');
});
});