shlink-web-client/test/utils/utils.test.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

import { capitalize, nonEmptyValueOrNull, rangeOf } from '../../src/utils/utils';
2019-01-08 23:19:38 +03:00
describe('utils', () => {
describe('rangeOf', () => {
2020-11-14 01:06:03 +03:00
const func = (i: number) => `result_${i}`;
const size = 5;
it('builds a range of specified size invike provided function', () => {
expect(rangeOf(size, func)).toEqual([
'result_1',
'result_2',
'result_3',
'result_4',
'result_5',
]);
});
it('builds a range starting at provided pos', () => {
const startAt = 3;
expect(rangeOf(size, func, startAt)).toEqual([
'result_3',
'result_4',
'result_5',
]);
});
});
describe('nonEmptyValueOrNull', () => {
it.each([
[ '', null ],
[ 'Hello', 'Hello' ],
[[], null ],
[[ 1, 2, 3 ], [ 1, 2, 3 ]],
[{}, null ],
[{ foo: 'bar' }, { foo: 'bar' }],
])('returns expected value based on input', (value, expected) => {
expect(nonEmptyValueOrNull(value)).toEqual(expected);
});
});
describe('capitalize', () => {
it.each([
[ 'foo', 'Foo' ],
[ 'BAR', 'BAR' ],
[ 'bAZ', 'BAZ' ],
[ 'with spaces', 'With spaces' ],
])('sets first letter in uppercase', (value, expectedResult) => {
expect(capitalize(value)).toEqual(expectedResult);
});
});
2019-01-08 23:19:38 +03:00
});