utils/ts-src/timeToMilliseconds.test.ts

66 lines
1.7 KiB
TypeScript
Raw Normal View History

import { timeToMilliseconds } from './timeToMilliseconds';
describe('Should convert strings into milliseconds', () => {
describe('Handle individual strings', () => {
test('Should handle seconds', () => {
expect(timeToMilliseconds('1s')).toEqual(1000);
expect(timeToMilliseconds('1sec')).toEqual(1000);
expect(timeToMilliseconds('1 second')).toEqual(1000);
});
test('Should handle minutes', () => {
expect(timeToMilliseconds('1m')).toEqual(60000);
expect(timeToMilliseconds('1min')).toEqual(60000);
expect(timeToMilliseconds('1 minutes')).toEqual(60000);
});
test('Should handle hours', () => {
expect(timeToMilliseconds('1h')).toEqual(3600000);
expect(timeToMilliseconds('1 hours')).toEqual(3600000);
});
test('Should handle days', () => {
expect(timeToMilliseconds('1d')).toEqual(86400000);
expect(timeToMilliseconds('1 days')).toEqual(86400000);
});
test('Should handle weeks', () => {
expect(timeToMilliseconds('1w')).toEqual(604800000);
expect(timeToMilliseconds('1 weeks')).toEqual(604800000);
});
test('Should handle years', () => {
expect(timeToMilliseconds('1y')).toEqual(31557600000);
expect(timeToMilliseconds('1 years')).toEqual(31557600000);
});
});
describe('Handle complex strings', () => {
test('Should handle 5y2w30d14h30m10s', () => {
expect(timeToMilliseconds('5y2w30d14h30m10s')).toEqual(161641810000);
});
test('1 hour and 5 seconds', () => {
expect(timeToMilliseconds('1 hour and 5 seconds')).toEqual(3605000);
});
});
describe('Handle complex strings', () => {
test('Should handle empty', () => {
expect(timeToMilliseconds('')).toEqual(0);
});
});
});