test: init packages/util/__tests__

This commit is contained in:
chenshenhai 2021-09-28 17:57:18 +08:00
parent edd6c5d676
commit 44b787ea25
2 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,33 @@
import util from '../src';
const types = {
time: 'Object',
loader: 'Object',
file: 'Object',
color: 'Object',
uuid: 'Object',
istype: 'Object',
data: 'Object',
}
function getType (data: any): string {
const typeStr = Object.prototype.toString.call(data) || '';
const result = typeStr.replace(/(\[object|\])/ig, '').trim();
return result;
}
describe('@idraw/util', () => {
test('index', async () => {
const keys = Object.keys(util);
keys.forEach((key) => {
// @ts-ignore
const type = getType(util[key]);
// @ts-ignore
expect(type).toStrictEqual(types[key]);
});
});
});

View file

@ -0,0 +1,28 @@
import {
toColorHexNum,
toColorHexStr,
isColorStr
} from '../../src/lib/color';
describe('@idraw/util: lib/color', () => {
const hex = '#f0f0f0';
const num = 15790320;
test('toColorHexNum', async () => {
const result = toColorHexNum(hex);
expect(result).toStrictEqual(num);
});
test('toColorHexStr', async () => {
const result = toColorHexStr(num);
expect(result).toStrictEqual(hex);
});
test('isColorStr', async () => {
const result = isColorStr(hex);
expect(result).toStrictEqual(true);
});
});