@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
45 lines (44 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("../..");
describe('msToUnit', () => {
it('convert milliseconds to milliseconds', () => {
const value = 1234;
const expected = 1234;
expect((0, __1.msToUnit)(value, __1.TimeUnit.Millisecond)).toBe(expected);
expect((0, __1.msToUnit)(value, __1.TimeUnit.Milliseconds)).toBe(expected);
});
it('convert milliseconds to seconds', () => {
const value = 3000;
const expected = 3;
expect((0, __1.msToUnit)(value, __1.TimeUnit.Second)).toBe(expected);
expect((0, __1.msToUnit)(value, __1.TimeUnit.Seconds)).toBe(expected);
});
it('convert milliseconds to minutes', () => {
const value = 720000;
const expected = 12;
expect((0, __1.msToUnit)(value, __1.TimeUnit.Minute)).toBe(expected);
expect((0, __1.msToUnit)(value, __1.TimeUnit.Minutes)).toBe(expected);
});
it('convert milliseconds to hours', () => {
const value = 79200000;
const expected = 22;
expect((0, __1.msToUnit)(value, __1.TimeUnit.Hour)).toBe(expected);
expect((0, __1.msToUnit)(value, __1.TimeUnit.Hours)).toBe(expected);
});
it('convert milliseconds to day', () => {
const value = 345600000;
const expected = 4;
expect((0, __1.msToUnit)(value, __1.TimeUnit.Day)).toBe(expected);
expect((0, __1.msToUnit)(value, __1.TimeUnit.Days)).toBe(expected);
});
it('convert milliseconds to weeks', () => {
const value = 1512000000;
const expected = 2.5;
expect((0, __1.msToUnit)(value, __1.TimeUnit.Week)).toBe(expected);
expect((0, __1.msToUnit)(value, __1.TimeUnit.Weeks)).toBe(expected);
});
it(`should throw an error if the unit is not supported`, () => {
expect(() => (0, __1.msToUnit)(1, 'foo')).toThrowError();
});
});