diff --git a/packages/util/__tests__/index.test.ts b/packages/util/__tests__/index.test.ts new file mode 100644 index 0000000..cbe1c6d --- /dev/null +++ b/packages/util/__tests__/index.test.ts @@ -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]); + }); + }); + +}); + diff --git a/packages/util/__tests__/lib/time.test.ts b/packages/util/__tests__/lib/time.test.ts new file mode 100644 index 0000000..3472723 --- /dev/null +++ b/packages/util/__tests__/lib/time.test.ts @@ -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); + }); + +}); +