mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
test: init packages/util/__tests__
This commit is contained in:
parent
edd6c5d676
commit
44b787ea25
2 changed files with 61 additions and 0 deletions
33
packages/util/__tests__/index.test.ts
Normal file
33
packages/util/__tests__/index.test.ts
Normal 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]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
28
packages/util/__tests__/lib/time.test.ts
Normal file
28
packages/util/__tests__/lib/time.test.ts
Normal 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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in a new issue