29 lines
713 B
TypeScript
29 lines
713 B
TypeScript
// Mock the useServerTime module before importing anything that uses it
|
|
jest.mock('@/hooks/useServerTime', () => ({
|
|
serverNow: jest.fn(() => new Date()),
|
|
}));
|
|
|
|
import { canBeConvertToDate } from '../src/utils/date';
|
|
|
|
describe('test canBeConvertToDate()', () => {
|
|
test('null', () => {
|
|
expect(canBeConvertToDate(null)).toBe(false);
|
|
});
|
|
|
|
test('undefined', () => {
|
|
expect(canBeConvertToDate(undefined)).toBe(false);
|
|
});
|
|
|
|
test('empty string', () => {
|
|
expect(canBeConvertToDate('')).toBe(false);
|
|
});
|
|
|
|
test('valid string', () => {
|
|
expect(canBeConvertToDate('2024-10-10T10:10:10+08:00')).toBe(true);
|
|
});
|
|
|
|
test('numeric', () => {
|
|
expect(canBeConvertToDate(0)).toBe(true);
|
|
});
|
|
});
|